diff --git a/src/checkbox/README.md b/src/checkbox/README.md index 289f20d3d..28693a217 100644 --- a/src/checkbox/README.md +++ b/src/checkbox/README.md @@ -184,7 +184,7 @@ export default { @click="toggle(index)" > @@ -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 diff --git a/src/checkbox/README.zh-CN.md b/src/checkbox/README.zh-CN.md index 25b1919ab..856877f6d 100644 --- a/src/checkbox/README.zh-CN.md +++ b/src/checkbox/README.zh-CN.md @@ -204,7 +204,7 @@ export default { @click="toggle(index)" > @@ -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(); - }, - }, }; ```