Vant: CellSwipe 滑动单元格 on-close 函数如何传参

Created on 3 Jul 2018  ·  3Comments  ·  Source: youzan/vant

<van-cell-swipe :right-width="65" :left-width="65" :on-close="onClose">
  <span slot="left">选择</span>
  <van-cell-group>
    <van-cell title="单元格" value="内容" />
  </van-cell-group>
  <span slot="right">删除</span>
</van-cell-swipe>
export default {
  methods: {
    onClose(clickPosition, instance) {
      switch (clickPosition) {
        case 'left':
        case 'cell':
        case 'outside':
          instance.close();
          break;
        case 'right':
          Dialog.confirm({
            message: '确定删除吗?'
          }).then(() => {
            instance.close();
          });
          break;
      }
    }
  }
}

onClose函数中如何才能知道我点击的是数组里面的哪个数据,怎样传递参数给此函数?从而删除对应的数据?

Most helpful comment

可以将onClose写为一个闭包
:on-close="onClose(item)"

onClose(item) {
      return function(clickPosition, instance){
  //....
  }
}

具体可看 #454

All 3 comments

可以将onClose写为一个闭包
:on-close="onClose(item)"

onClose(item) {
      return function(clickPosition, instance){
  //....
  }
}

具体可看 #454

大神 恕我愚昧

以后遇到这样的情况,都可以这样解决了。

Was this page helpful?
0 / 5 - 0 ratings