关于火狐浏览器在drag事件拖拽时 自动打开窗口的问题
定义 dragstart 事件
<div class="iconCon">
<div
v-for="(item,index) in iconArr"
:key="index"
class="device-item"
:draggable="true"
@dragstart="dragStartOnList($event, item)"
>
<img class="item-cone" :src="item.icon" alt="" :title="item.name">
<div class="item-name">{{item.name}}</div>
</div>
</div>
阻止默认事件的方法
dragStartOnList(event,item){
this.isDragOnMap = false;
this.offset.x = event.offsetX;
this.offset.y = event.offsetY;
// event.dataTransfer.setData('device',JSON.stringify(item));
// 替换为 localStorage
localStorage.setItem('device',JSON.stringify(item))
// 阻止默认事件
document.body.ondrop = function(event) {
event.preventDefault()
event.stopPropagation()
}
},
document.body.ondrop = function(event) {
event.preventDefault()
event.stopPropagation()
}