动态的添加和获取-ref

4次阅读

共计 439 个字符,预计需要花费 2 分钟才能阅读完成。

1. 在项目中使用 vant 的 van-swipe-cell,需要动态的获取当前的 ref 的值
2. 具体方法

 <div  v-for="item in crewData" :key='item.id'>
   <van-swipe-cell :ref="`crewData${item.id}`">

获取的

   openswipCell (event, item) {this.$refs[`crewData${item.id}`][0].open('right')
    },

深入的,因为需要在循环体(也就是父盒子内部实现点击)

`

   openswipCell (event, item) {event.stopPropagation();
      if (this.$refs[`crewData${item.id}`][0].offset) {this.$refs[`crewData${item.id}`][0].close();
        return;
      }
      this.$refs[`crewData${item.id}`][0].open('right')
    },

`

正文完
 0