...

Vuejs - eventListener prevent drag/drop

Добавяне на eventListener върху елемент за при драг/дроп и т.н.
преди 2 месеца

Добавяне на eventListener върху елемент за при драг/дроп и т.н.

mounted(){
                 /*
                  Listen to all of the drag events and bind an event listener to each
                  for the fileform.
                */
                ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop'].forEach( function( evt ) {
                    /*
                      For each event add an event listener that prevents the default action
                      (opening the file in the browser) and stop the propagation of the event (so
                      no other elements open the file in the browser)
                    */
                    this.$refs.fileform.addEventListener(evt, function(e){
                        e.preventDefault();
                        e.stopPropagation();
                    }.bind(this), false);
                }.bind(this));

                /*
                  Add an event listener for drop to the form
                */
                this.addEventListener('drop', function(e){
                    /*
                      Capture the files from the drop event and add them to our local files
                      array.
                    */
                    // for( let i = 0; i < e.dataTransfer.files.length; i++ ){
                    //     this.files.push( e.dataTransfer.files[i] );
                    // }
                    console.log(e);
                }.bind(this));
}