在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)  HTML/ VUE是否有必要利用事件委托

VUE是否有必要利用事件委托

VUE是否有必要利用事件委托,還是VUE底層源碼已經(jīng)進(jìn)行過(guò)處理!
例如
<ul>
<li v-for="....."></li>
</ul>
這種的話在UL標(biāo)簽上添加事件好,還是在LI上添加事件?還是說(shuō)VUE在底層已經(jīng)進(jìn)行過(guò)處理,無(wú)所謂在哪里添加事件?

回答
編輯回答
念初

官方不推薦使用事件委托。

Is event delegation necessary?

Well, delegation has two main advantages: one is practical - it saves you from having to add (and remove!!) those listeners individually. But Vue already does that for you.

The other one is performance / memory. But since every click listener in a v-vor loop would use the same callback, this is minimal unless you have hundreds or thousands of rows.

And finally, you can use delegation pretty easily by adding an @click listener to the <ul> element instead of the children. But then you have to resort to checks on the click target to evaluate which item in your data it might represent. So I would only use that if you truly find any performance problems without delegation.

2017年12月20日 00:57