From f354513f9e6147f712629ffd9a9ccb8e59622a99 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 9 Dec 2020 10:33:00 +0800 Subject: [PATCH] docs(Switch): use composition api --- src/switch/README.md | 31 ++++++++++++++++++------------- src/switch/README.zh-CN.md | 31 ++++++++++++++++++------------- src/switch/demo/index.vue | 38 ++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/switch/README.md b/src/switch/README.md index 082a42c84..df163661c 100644 --- a/src/switch/README.md +++ b/src/switch/README.md @@ -19,11 +19,12 @@ app.use(Switch); ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - checked: true, - }; + setup() { + const checked = ref(true); + return { checked }; }, }; ``` @@ -59,21 +60,25 @@ export default { ``` ```js +import { ref } from 'vue'; +import { Dialog } from 'vant'; + export default { - data() { - return { - checked: true, - }; - }, - methods: { - onUpdateValue(checked) { + setup() { + const checked = ref(true); + const onUpdateValue = (newValue) => { Dialog.confirm({ title: 'Confirm', message: 'Are you sure to toggle switch?', }).then(() => { - this.checked = checked; + checked.value = newValue; }); - }, + }; + + return { + checked, + onUpdateValue, + }; }, }; ``` diff --git a/src/switch/README.zh-CN.md b/src/switch/README.zh-CN.md index c51cb0aa1..dc5f8fd22 100644 --- a/src/switch/README.zh-CN.md +++ b/src/switch/README.zh-CN.md @@ -25,11 +25,12 @@ app.use(Switch); ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - checked: true, - }; + setup() { + const checked = ref(true); + return { checked }; }, }; ``` @@ -75,21 +76,25 @@ export default { ``` ```js +import { ref } from 'vue'; +import { Dialog } from 'vant'; + export default { - data() { - return { - checked: true, - }; - }, - methods: { - onUpdateValue(checked) { + setup() { + const checked = ref(true); + const onUpdateValue = (newValue) => { Dialog.confirm({ title: '提醒', message: '是否切换开关?', }).then(() => { - this.checked = checked; + checked.value = newValue; }); - }, + }; + + return { + checked, + onUpdateValue, + }; }, }; ``` diff --git a/src/switch/demo/index.vue b/src/switch/demo/index.vue index 744a1903a..5c163e49e 100644 --- a/src/switch/demo/index.vue +++ b/src/switch/demo/index.vue @@ -24,7 +24,7 @@ - + @@ -37,6 +37,10 @@