docs(Checkbox): fix toggle demo

This commit is contained in:
chenjiahan 2020-09-01 16:33:26 +08:00
parent c3ad8bf5c4
commit 54c4a0c3c8
2 changed files with 36 additions and 18 deletions

View File

@ -184,7 +184,7 @@ export default {
@click="toggle(index)"
>
<template #right-icon>
<van-checkbox :name="item" ref="checkboxes" />
<van-checkbox :name="item" :ref="el => checkboxes[index] = el" />
</template>
</van-cell>
</van-cell-group>
@ -192,19 +192,28 @@ export default {
```
```js
import { ref, onBeforeUpdate } from 'vue';
export default {
data() {
setup() {
const result = ref([]);
const checkboxes = ref([]);
const toggle = (index) => {
checkboxes.value[index].toggle();
};
onBeforeUpdate(() => {
checkboxes.value = [];
});
return {
list: ['a', 'b']
result: []
list: ['a', 'b'],
result,
toggle,
checkboxes,
};
},
methods: {
toggle(index) {
this.$refs.checkboxes[index].toggle();
}
}
}
};
```
## API

View File

@ -204,7 +204,7 @@ export default {
@click="toggle(index)"
>
<template #right-icon>
<van-checkbox :name="item" ref="checkboxes" />
<van-checkbox :name="item" :ref="el => checkboxes[index] = el" />
</template>
</van-cell>
</van-cell-group>
@ -212,18 +212,27 @@ export default {
```
```js
import { ref, onBeforeUpdate } from 'vue';
export default {
data() {
setup() {
const result = ref([]);
const checkboxes = ref([]);
const toggle = (index) => {
checkboxes.value[index].toggle();
};
onBeforeUpdate(() => {
checkboxes.value = [];
});
return {
list: ['a', 'b'],
result: [],
result,
toggle,
checkboxes,
};
},
methods: {
toggle(index) {
this.$refs.checkboxes[index].toggle();
},
},
};
```