vant checkbox 为什么会拿不到值?


 <van-checkbox-group v-model="result" ref="checkboxGroup">
      <van-cell-group>
        <van-cell
          v-for="(item, index) in glist"
          clickable
          :key="index"
          :title="`复选框 ${item}`"
          @click="togglse(index)"
        >
          <template #right-icon>
            <van-checkbox :name="item" ref="checkboxes" />
          </template>
        </van-cell>
      </van-cell-group>
    </van-checkbox-group>

 togglse(index) {
      this.$refs.checkboxes[index].toggle()
      console.log(this.result)
    },

img
可以看到点第一个时候是拿不到值,点第二个可以拿到第一次的,为什么会延迟?要怎么才能拿到完整的

我也遇到了这个问题 因为是异步操作 ,需要将 console.log(this.result) 用定时器包裹起来

setTimeout(() => {
        console.log(this.result)
      }, 0) 

如果问题得到了解决,麻烦动动小手关注一下

ref="checkboxes" 这个得唯一

我现在也碰到这个问题,你解决了吗

@click的方法写到van-checkbox标签里头