mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(Checkbox): fix toggle demo
This commit is contained in:
parent
c3ad8bf5c4
commit
54c4a0c3c8
@ -184,7 +184,7 @@ export default {
|
|||||||
@click="toggle(index)"
|
@click="toggle(index)"
|
||||||
>
|
>
|
||||||
<template #right-icon>
|
<template #right-icon>
|
||||||
<van-checkbox :name="item" ref="checkboxes" />
|
<van-checkbox :name="item" :ref="el => checkboxes[index] = el" />
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
@ -192,19 +192,28 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref, onBeforeUpdate } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const result = ref([]);
|
||||||
|
const checkboxes = ref([]);
|
||||||
|
const toggle = (index) => {
|
||||||
|
checkboxes.value[index].toggle();
|
||||||
|
};
|
||||||
|
|
||||||
|
onBeforeUpdate(() => {
|
||||||
|
checkboxes.value = [];
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list: ['a', 'b']
|
list: ['a', 'b'],
|
||||||
result: []
|
result,
|
||||||
|
toggle,
|
||||||
|
checkboxes,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
};
|
||||||
toggle(index) {
|
|
||||||
this.$refs.checkboxes[index].toggle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
@ -204,7 +204,7 @@ export default {
|
|||||||
@click="toggle(index)"
|
@click="toggle(index)"
|
||||||
>
|
>
|
||||||
<template #right-icon>
|
<template #right-icon>
|
||||||
<van-checkbox :name="item" ref="checkboxes" />
|
<van-checkbox :name="item" :ref="el => checkboxes[index] = el" />
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
@ -212,18 +212,27 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref, onBeforeUpdate } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const result = ref([]);
|
||||||
|
const checkboxes = ref([]);
|
||||||
|
const toggle = (index) => {
|
||||||
|
checkboxes.value[index].toggle();
|
||||||
|
};
|
||||||
|
|
||||||
|
onBeforeUpdate(() => {
|
||||||
|
checkboxes.value = [];
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list: ['a', 'b'],
|
list: ['a', 'b'],
|
||||||
result: [],
|
result,
|
||||||
|
toggle,
|
||||||
|
checkboxes,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
toggle(index) {
|
|
||||||
this.$refs.checkboxes[index].toggle();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user