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
import { reactive } from 'vue';
import { Toast } from 'vant';
export default {
data() {
return {
currentContact: {
name: 'John Snow',
tel: '13000000000',
},
};
},
methods: {
onEdit() {
setup() {
const currentContact = reactive({
name: 'John Snow',
tel: '13000000000',
});
const onEdit = () => {
Toast('edit');
},
};
return {
onEdit,
currentContact,
};
},
};
```

View File

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

View File

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