vant icon indicating copy to clipboard operation
vant copied to clipboard

上传组件被套在v-for循环中,会自动重复触发

Open lvkunpeng opened this issue 8 years ago • 2 comments

bug描述

在一个v-for循环的dom结构中,循环出了n个van-uploader组件,每次需要明确的知道触发的index从而渲染到对应的data中,我利用了:before-read="setIndex(index)" 方法设置了一个全局变量index。但是每次结果都是这个行为会触发n次(也就是上传组件的length的数目)最后得到的index永远是length。请问这个是不是有其他的解决办法

Screenshots image

Environment

  • Device: mobile
  • Browser: chrome
  • Vant Version: ^1.1.0

Reproduce Provide the steps to reproduce and if possible a minimal demo of the problem via jsfiddle. https://jsfiddle.net/dfarLdko/1/

lvkunpeng avatar Jun 19 '18 14:06 lvkunpeng

这样的写法是有问题的,在 Vue 模板中通过 props 传入带括号的函数会立即执行 可以使用下面的写法:

export default {
  methods: {
    beforeRead(index) {
      return file => {
        console.log(index, file);
      };
    }
  }
}

chenjiahan avatar Jun 20 '18 12:06 chenjiahan

image 这个怎么解决,然后我测试了一下,发现好奇怪的现象 image 给数组1下push 数据

TKYV avatar May 09 '20 17:05 TKYV