docs(ContactCard): use composition api

This commit is contained in:
chenjiahan
2020-12-15 14:48:19 +08:00
parent 43a7047326
commit 25634382f6
3 changed files with 67 additions and 54 deletions

View File

@@ -42,21 +42,24 @@ export default {
``` ```
```js ```js
import { reactive } from 'vue';
import { Toast } from 'vant'; import { Toast } from 'vant';
export default { export default {
data() { setup() {
return { const currentContact = reactive({
currentContact: {
name: 'John Snow', name: 'John Snow',
tel: '13000000000', tel: '13000000000',
}, });
};
}, const onEdit = () => {
methods: {
onEdit() {
Toast('edit'); Toast('edit');
}, };
return {
onEdit,
currentContact,
};
}, },
}; };
``` ```

View File

@@ -46,21 +46,24 @@ export default {
``` ```
```js ```js
import { reactive } from 'vue';
import { Toast } from 'vant'; import { Toast } from 'vant';
export default { export default {
data() { setup() {
return { const currentContact = reactive({
currentContact: {
name: '张三', name: '张三',
tel: '13000000000', tel: '13000000000',
}, });
const onEdit = () => {
Toast('edit');
};
return {
onEdit,
currentContact,
}; };
},
methods: {
onEdit() {
Toast('编辑');
},
}, },
}; };
``` ```

View File

@@ -22,11 +22,12 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { computed } from 'vue';
import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
add: '新增', add: '新增',
edit: '编辑', edit: '编辑',
@@ -41,25 +42,31 @@ export default {
addContact: 'Add Contact', addContact: 'Add Contact',
editContact: 'Edit Contact', editContact: 'Edit Contact',
}, },
}, };
computed: { export default {
currentContact() { setup() {
return { const t = useTranslate(i18n);
name: this.t('name'),
const currentContact = computed(() => ({
name: t('name'),
tel: '13000000000', tel: '13000000000',
}));
const onAdd = () => {
Toast(t('add'));
}; };
},
},
methods: { const onEdit = () => {
onAdd() { Toast(t('edit'));
Toast(this.t('add')); };
},
onEdit() { return {
Toast(this.t('edit')); t,
}, onAdd,
onEdit,
currentContact,
};
}, },
}; };
</script> </script>