docs(ContactEdit): use composition api

This commit is contained in:
chenjiahan 2020-12-13 14:23:36 +08:00
parent 4d888702de
commit 03e65d9427
3 changed files with 54 additions and 40 deletions

View File

@ -26,21 +26,24 @@ app.use(ContactEdit);
```
```js
import { ref } from 'vue';
import { Toast } from 'vant';
export default {
data() {
return {
editingContact: {},
};
},
methods: {
onSave(contactInfo) {
setup() {
const editingContact = ref({});
const onSave = (contactInfo) => {
Toast('Save');
},
onDelete(contactInfo) {
};
const onDelete = (contactInfo) => {
Toast('Delete');
},
};
return {
onSave,
onDelete,
editingContact,
};
},
};
```

View File

@ -30,21 +30,24 @@ app.use(ContactEdit);
```
```js
import { ref } from 'vue';
import { Toast } from 'vant';
export default {
data() {
return {
editingContact: {},
};
},
methods: {
onSave(contactInfo) {
setup() {
const editingContact = ref({});
const onSave = (contactInfo) => {
Toast('保存');
},
onDelete(contactInfo) {
};
const onDelete = (contactInfo) => {
Toast('删除');
},
};
return {
onSave,
onDelete,
editingContact,
};
},
};
```

View File

@ -11,30 +11,38 @@
</demo-block>
</template>
<script>
<script lang="ts">
import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast';
const i18n = {
'zh-CN': {
defaultLabel: '设为默认联系人',
},
'en-US': {
defaultLabel: 'Set as the default contact',
},
};
export default {
i18n: {
'zh-CN': {
defaultLabel: '设为默认联系人',
},
'en-US': {
defaultLabel: 'Set as the default contact',
},
},
setup() {
const t = useTranslate(i18n);
const editingContact = ref({});
data() {
return {
editingContact: {},
const onSave = () => {
Toast(t('save'));
};
const onDelete = () => {
Toast(t('delete'));
};
},
methods: {
onSave() {
this.$toast(this.t('save'));
},
onDelete() {
this.$toast(this.t('delete'));
},
return {
t,
onSave,
onDelete,
editingContact,
};
},
};
</script>