vue中使用v-on绑定事件中,获取$event.currentTarget,日志打印为null
生活随笔
收集整理的這篇文章主要介紹了
vue中使用v-on绑定事件中,获取$event.currentTarget,日志打印为null
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題: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也沒有問題
轉載于:https://www.cnblogs.com/zuozuo-blog/p/11158407.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的vue中使用v-on绑定事件中,获取$event.currentTarget,日志打印为null的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js Object的属性 Configu
- 下一篇: HTTP版本