From f9b6fda65cd35fc6b9d4ed1be7f4eb0853dea618 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 13 Dec 2020 14:15:36 +0800 Subject: [PATCH] docs(Tabbar): use composition api --- src/tabbar/README.md | 63 +++++++++------ src/tabbar/README.zh-CN.md | 63 +++++++++------ src/tabbar/demo/index.vue | 76 ++++++++++--------- .../test/__snapshots__/demo.spec.js.snap | 8 +- 4 files changed, 121 insertions(+), 89 deletions(-) diff --git a/src/tabbar/README.md b/src/tabbar/README.md index 6ce505134..8fd2b286b 100644 --- a/src/tabbar/README.md +++ b/src/tabbar/README.md @@ -25,11 +25,12 @@ app.use(TabbarItem); ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - active: 0, - }; + setup() { + const active = ref(0); + return { active }; }, }; ``` @@ -46,11 +47,12 @@ export default { ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - active: 'home', - }; + setup() { + const active = ref('home'); + return { active }; }, }; ``` @@ -84,14 +86,18 @@ Use `icon` slot to custom icon. ``` ```js +import { ref } from 'vue'; + export default { - data() { + setup() { + const active = ref(0); + const icon = { + active: 'https://img.yzcdn.cn/vant/user-active.png', + inactive: 'https://img.yzcdn.cn/vant/user-inactive.png', + }; return { - active: 0, - icon: { - active: 'https://img.yzcdn.cn/vant/user-active.png', - inactive: 'https://img.yzcdn.cn/vant/user-inactive.png', - }, + icon, + active, }; }, }; @@ -112,21 +118,28 @@ export default { ```html - Tab1 - Tab2 - Tab3 - Tab4 + Tab 1 + Tab 2 + Tab 3 + Tab 4 ``` ```js -import { Notify } from 'vant'; +import { ref } from 'vue'; +import { Toast } from 'vant'; export default { - methods: { - onChange(index) { - Notify({ type: 'primary', message: index }); - }, + setup() { + const active = ref(0); + const onChange = (index) => { + Toast(`Tab ${index}`); + }; + + return { + icon, + onChange, + }; }, }; ``` @@ -137,8 +150,8 @@ export default { - Tab - Tab + Tab + Tab ``` diff --git a/src/tabbar/README.zh-CN.md b/src/tabbar/README.zh-CN.md index bbb0dc04f..e2ee0b5fa 100644 --- a/src/tabbar/README.zh-CN.md +++ b/src/tabbar/README.zh-CN.md @@ -27,11 +27,12 @@ app.use(TabbarItem); ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - active: 0, - }; + setup() { + const active = ref(0); + return { active }; }, }; ``` @@ -50,11 +51,12 @@ export default { ``` ```js +import { ref } from 'vue'; + export default { - data() { - return { - active: 'home', - }; + setup() { + const active = ref('home'); + return { active }; }, }; ``` @@ -90,14 +92,18 @@ export default { ``` ```js +import { ref } from 'vue'; + export default { - data() { + setup() { + const active = ref(0); + const icon = { + active: 'https://img.yzcdn.cn/vant/user-active.png', + inactive: 'https://img.yzcdn.cn/vant/user-inactive.png', + }; return { - active: 0, - icon: { - active: 'https://img.yzcdn.cn/vant/user-active.png', - inactive: 'https://img.yzcdn.cn/vant/user-inactive.png', - }, + icon, + active, }; }, }; @@ -118,21 +124,28 @@ export default { ```html - 标签1 - 标签2 - 标签3 - 标签4 + 标签 1 + 标签 2 + 标签 3 + 标签 4 ``` ```js -import { Notify } from 'vant'; +import { ref } from 'vue'; +import { Toast } from 'vant'; export default { - methods: { - onChange(index) { - Notify({ type: 'primary', message: index }); - }, + setup() { + const active = ref(0); + const onChange = (index) => { + Toast(`标签 ${index}`); + }; + + return { + icon, + onChange, + }; }, }; ``` @@ -145,8 +158,8 @@ export default { - 标签 - 标签 + 标签 + 标签 ``` diff --git a/src/tabbar/demo/index.vue b/src/tabbar/demo/index.vue index a808525b6..341b6c385 100644 --- a/src/tabbar/demo/index.vue +++ b/src/tabbar/demo/index.vue @@ -62,58 +62,64 @@ - {{ t('tab') + 1 }} - {{ t('tab') + 2 }} - {{ t('tab') + 3 }} - {{ t('tab') + 4 }} + {{ `${t('tab')} 1` }} + {{ `${t('tab')} 2` }} + {{ `${t('tab')} 3` }} + {{ `${t('tab')} 4` }} - diff --git a/src/tabbar/test/__snapshots__/demo.spec.js.snap b/src/tabbar/test/__snapshots__/demo.spec.js.snap index 5907f7f1c..0c7999dfe 100644 --- a/src/tabbar/test/__snapshots__/demo.spec.js.snap +++ b/src/tabbar/test/__snapshots__/demo.spec.js.snap @@ -220,7 +220,7 @@ exports[`should render demo and match snapshot 1`] = `
- Tab1 + Tab 1
@@ -229,7 +229,7 @@ exports[`should render demo and match snapshot 1`] = `
- Tab2 + Tab 2
@@ -238,7 +238,7 @@ exports[`should render demo and match snapshot 1`] = `
- Tab3 + Tab 3
@@ -247,7 +247,7 @@ exports[`should render demo and match snapshot 1`] = `
- Tab4 + Tab 4