模板代碼<div style="position:absolute"
:style="{
width:width+'px',
height:height+'px',
left:left+'px',
top:top+'px',
backgroundColor
}"
@mousedown="onMouseDown($event)"></div>腳本代碼methods:{ onMouseDown:(e)=>{ let count = 0; this.inDragging = true;//這里的this指定元素而不是期望的組件實(shí)例
window.addEventListener('mousemove',this.onDragging);
},
}
1 回答

慕田峪9158850
TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個(gè)贊
原因:箭頭函數(shù)的 this 的指向機(jī)制
解決:不要用箭頭函數(shù)
onMouseDown(e) { let count = 0; this.inDragging = true; window.addEventListener('mousemove',this.onDragging); },
添加回答
舉報(bào)
0/150
提交
取消