I'm currently developing a drag-and-drop web application using Vue.JS and Vuex Store. The drag-and-drop functionality is based on the HTML Drag and Drop API as outlined in the Mozilla documentation. I have successfully implemented the Dropzone Component and Draggable Element Components with event.preventDefault(). With nested Dropzones, I had to use event.stopPropagation() on the Dropzones to ensure proper functionality. Overall, the drag-and-drop feature works as intended.
However, I encountered an issue where if a user drops a Draggable Element outside of a valid Dropzone, it causes the UI to break. Therefore, I am looking for a solution to implement an app-wide event listener for drops in non-valid dropzone areas.
I initially attempted to create a global "dragend" listener, but it did not work as expected. I also experimented with using "mouseup" event, but it seemed too general. Here is an example of what I tried:
new Vue({
router,
store,
render: (h) => h(App),
async created() {
window.document.addEventListener('dragend', (e) => {
console.log("global Dragend -------------- ");
})
window.document.addEventListener('mouseup', (e) => {
console.log("global Mouseup -------------- ");
})
},
}).$mount('#app');
If anyone has a solution or suggestion on how to implement an app-wide event listener that triggers after failed drops, I would greatly appreciate the assistance.