美文网首页
【转载】vue中v-for循环出来的元素绑定的不同事件

【转载】vue中v-for循环出来的元素绑定的不同事件

作者: 优秀的收藏转载分享 | 来源:发表于2020-08-05 17:56 被阅读0次

原文:vue中v-for循环出来的元素绑定的不同事件(亲测,好用😁)

   <div style="padding: 0 5px;" @click="handler(item.fun)" v-for="(item, index) in iconData" :key="index">
    <i class="iconfont  iconHover" :class="item.icon" :title="item.title"></i>
   </div>

刚开始我在循环出来的元素中加@click="item.fun",出现了handler.apply is not a function的错误。然后网上查了一下,可以通过一个方法间接调用来实现。

      iconData: [
        { icon: 'iconquanxuan', title: '全选', fun: 'checkAll' },
        { icon: 'iconfanxuan', title: '反选', fun: 'toggleAll' },
        { icon: 'iconzhongzhi', title: '重置', fun: 'cancleAll' }
      ]
    handler(fun) {
      this[fun]()
    },
    checkAll() {
      this.checkedList = [...this.Options]
      viewer.bimAdmin.tools['Bim.TilesetModelList'].toggleAllOff()
    },
    cancleAll() {
      this.checkedList = []
      viewer.bimAdmin.tools['Bim.TilesetModelList'].toggleAllOn()
    },
    toggleAll() {
      //反选
      this.checkedList = this.Options.filter(a => this.checkedList.indexOf(a) === -1)
      viewer.bimAdmin.tools['Bim.TilesetModelList'].toggleAll()
    },

相关文章

网友评论

      本文标题:【转载】vue中v-for循环出来的元素绑定的不同事件

      本文链接:https://www.haomeiwen.com/subject/hbyorktx.html