mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(ContactCard): use composition api
This commit is contained in:
parent
43a7047326
commit
25634382f6
@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
@ -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('编辑');
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user