問題:vue中使用v-on綁定事件中,獲取$event.currentTarget,日志打印為null
dom結構: <li @click="clickEvent('hello',$event)"> <span>內部元素</span> </li> 事件代碼: clickEvent(str,event){ console.log(event) }
結果為:
問題說明:
e.currentTarget是一個瞬時的值,當打印event后,等到展開log信息時,冒泡事件已經結束,所以當前currentTarget是null
解決方法:
console.log(event.currentTarget) 能正確顯示
代碼中正常使用event.currentTarget也沒有問題