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也沒有問題









免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM