Electron-vue: How use File Object

Created on 22 Aug 2017  路  6Comments  路  Source: SimulatedGREG/electron-vue

Most helpful comment

@hoythan

This is more of a question and not a direct issue with electron-vue. But to help a little, here is an example of how I previously handled getting files using drag-and-drop.

https://github.com/SimulatedGREG/asar-explorer/blob/master/src/renderer/components/Open.vue

All 6 comments

            const holder = document.getElementById('holder')
            holder.ondragover = () => {
                return false;
            }
            holder.ondragleave = holder.ondragend = () => {
                return false;
            }
            holder.ondrop = (e) => {
                e.preventDefault()
                for (let f of e.dataTransfer.files) {
                    console.log('File(s) you dragged here: ', f.path)
                }
                return false;
            }

console

Error in created hook: "TypeError: Cannot set property 'ondragover' of null"

i drag file to input element , it open the save window?

I used the method to bind events on the window to resolve it

            window.ondragover = function(e) {
                return false
            };

            window.ondrop = function(e) {
                e.preventDefault();
                for (var i = 0; i < e.dataTransfer.files.length; ++i) {
                    console.log(e.dataTransfer.files[i].path);
                }
                return false;
            };

            window.ondragleave = function () {
                return false;
            };

error log

Property or method "onDrop" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

@hoythan

This is more of a question and not a direct issue with electron-vue. But to help a little, here is an example of how I previously handled getting files using drag-and-drop.

https://github.com/SimulatedGREG/asar-explorer/blob/master/src/renderer/components/Open.vue

Thank you very much

Was this page helpful?
0 / 5 - 0 ratings