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,44 +22,51 @@
</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';
const i18n = {
'zh-CN': {
add: '新增',
edit: '编辑',
name: '张三',
addContact: '添加联系人',
editContact: '编辑联系人',
},
'en-US': {
add: 'Add',
edit: 'Edit',
name: 'John Snow',
addContact: 'Add Contact',
editContact: 'Edit Contact',
},
};
export default { export default {
i18n: { setup() {
'zh-CN': { const t = useTranslate(i18n);
add: '新增',
edit: '编辑',
name: '张三',
addContact: '添加联系人',
editContact: '编辑联系人',
},
'en-US': {
add: 'Add',
edit: 'Edit',
name: 'John Snow',
addContact: 'Add Contact',
editContact: 'Edit Contact',
},
},
computed: { const currentContact = computed(() => ({
currentContact() { name: t('name'),
return { tel: '13000000000',
name: this.t('name'), }));
tel: '13000000000',
};
},
},
methods: { const onAdd = () => {
onAdd() { Toast(t('add'));
Toast(this.t('add')); };
},
onEdit() { const onEdit = () => {
Toast(this.t('edit')); Toast(t('edit'));
}, };
return {
t,
onAdd,
onEdit,
currentContact,
};
}, },
}; };
</script> </script>