docs(checkbox): fix cell demo #7039

This commit is contained in:
chenjiahan 2020-08-29 19:37:43 +08:00
parent 8d3d944594
commit 2c55fed8b7

View File

@ -96,7 +96,7 @@
@click="toggle(index)" @click="toggle(index)"
> >
<template #right-icon> <template #right-icon>
<van-checkbox ref="checkboxes" :name="item" /> <van-checkbox :ref="setRefs(index)" :name="item" />
</template> </template>
</van-cell> </van-cell>
</van-cell-group> </van-cell-group>
@ -106,6 +106,9 @@
</template> </template>
<script> <script>
import { ref } from 'vue';
import { useRefs } from '../../composition/use-refs';
export default { export default {
i18n: { i18n: {
'zh-CN': { 'zh-CN': {
@ -140,6 +143,31 @@ export default {
}, },
}, },
setup() {
const group = ref();
const [refs, setRefs] = useRefs();
const toggle = (index) => {
refs.value[index].toggle();
};
const checkAll = () => {
group.value.toggleAll(true);
};
const toggleAll = () => {
group.value.toggleAll();
};
return {
group,
toggle,
setRefs,
checkAll,
toggleAll,
};
},
data() { data() {
return { return {
checkbox1: true, checkbox1: true,
@ -158,21 +186,6 @@ export default {
inactiveIcon: 'https://img.yzcdn.cn/vant/user-inactive.png', inactiveIcon: 'https://img.yzcdn.cn/vant/user-inactive.png',
}; };
}, },
methods: {
toggle(index) {
// TODO ref in for
this.$refs.checkboxes[index].toggle();
},
checkAll() {
this.$refs.group.toggleAll(true);
},
toggleAll() {
this.$refs.group.toggleAll();
},
},
}; };
</script> </script>