vue directive指令在v-for中冲突问题

返回
Author Avatar
钢翼
2019-03-03
编程
336

网上查的原因是由于vue的v-for 会复用子元素导致,

在绑定事件中制定唯一id可解决

Vue.directive('yourctrl', {
    bind: function (el, binding, vnode) {
        vnode.key = getNextId();//不可以用唯一id,会导致渲染多次的问题
    },
   ......
}