mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(ContactList): use composition api
This commit is contained in:
parent
03e65d9427
commit
540ffb6a4c
@ -26,11 +26,12 @@ app.use(ContactList);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { reactive } from 'vue';
|
||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const state = reactive({
|
||||||
chosenContactId: '1',
|
chosenContactId: '1',
|
||||||
list: [
|
list: [
|
||||||
{
|
{
|
||||||
@ -45,18 +46,24 @@ export default {
|
|||||||
tel: '1310000000',
|
tel: '1310000000',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
});
|
||||||
},
|
|
||||||
methods: {
|
const onAdd = () => {
|
||||||
onAdd() {
|
|
||||||
Toast('Add');
|
Toast('Add');
|
||||||
},
|
};
|
||||||
onEdit(contact) {
|
const onEdit = (contact) => {
|
||||||
Toast('Edit' + contact.id);
|
Toast('Edit' + contact.id);
|
||||||
},
|
};
|
||||||
onSelect(contact) {
|
const onSelect = (contact) => {
|
||||||
Toast('Select' + contact.id);
|
Toast('Select' + contact.id);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
state,
|
||||||
|
onAdd,
|
||||||
|
onEdit,
|
||||||
|
onSelect,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -20,8 +20,8 @@ app.use(ContactList);
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<van-contact-list
|
<van-contact-list
|
||||||
v-model="chosenContactId"
|
v-model="state.chosenContactId"
|
||||||
:list="list"
|
:list="state.list"
|
||||||
default-tag-text="默认"
|
default-tag-text="默认"
|
||||||
@add="onAdd"
|
@add="onAdd"
|
||||||
@edit="onEdit"
|
@edit="onEdit"
|
||||||
@ -30,11 +30,12 @@ app.use(ContactList);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { reactive } from 'vue';
|
||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const state = reactive({
|
||||||
chosenContactId: '1',
|
chosenContactId: '1',
|
||||||
list: [
|
list: [
|
||||||
{
|
{
|
||||||
@ -49,18 +50,24 @@ export default {
|
|||||||
tel: '1310000000',
|
tel: '1310000000',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
});
|
||||||
},
|
|
||||||
methods: {
|
const onAdd = () => {
|
||||||
onAdd() {
|
|
||||||
Toast('新增');
|
Toast('新增');
|
||||||
},
|
};
|
||||||
onEdit(contact) {
|
const onEdit = (contact) => {
|
||||||
Toast('编辑' + contact.id);
|
Toast('编辑' + contact.id);
|
||||||
},
|
};
|
||||||
onSelect(contact) {
|
const onSelect = (contact) => {
|
||||||
Toast('选择' + contact.id);
|
Toast('选择' + contact.id);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
state,
|
||||||
|
onAdd,
|
||||||
|
onEdit,
|
||||||
|
onSelect,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
</demo-block>
|
</demo-block>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
export default {
|
import { ref } from 'vue';
|
||||||
i18n: {
|
import { useTranslate } from '@demo/use-translate';
|
||||||
|
import Toast from '../../toast';
|
||||||
|
|
||||||
|
const i18n = {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
add: '新增',
|
add: '新增',
|
||||||
edit: '编辑',
|
edit: '编辑',
|
||||||
@ -52,24 +55,30 @@ export default {
|
|||||||
select: 'Select',
|
select: 'Select',
|
||||||
defaultTagText: 'default',
|
defaultTagText: 'default',
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
chosenContactId: '1',
|
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
export default {
|
||||||
onAdd() {
|
setup() {
|
||||||
this.$toast(this.t('add'));
|
const t = useTranslate(i18n);
|
||||||
},
|
const chosenContactId = ref('1');
|
||||||
onEdit(contact) {
|
|
||||||
this.$toast(this.t('edit') + contact.id);
|
const onAdd = () => {
|
||||||
},
|
Toast(t('add'));
|
||||||
onSelect(contact) {
|
};
|
||||||
this.$toast(this.t('select') + contact.id);
|
const onEdit = (contact: { id: string }) => {
|
||||||
},
|
Toast(t('edit') + contact.id);
|
||||||
|
};
|
||||||
|
const onSelect = (contact: { id: string }) => {
|
||||||
|
Toast(t('select') + contact.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
t,
|
||||||
|
onAdd,
|
||||||
|
onEdit,
|
||||||
|
onSelect,
|
||||||
|
chosenContactId,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -82,7 +82,6 @@ const i18n = {
|
|||||||
customColor: '自定义颜色',
|
customColor: '自定义颜色',
|
||||||
matchByName: '通过名称匹配',
|
matchByName: '通过名称匹配',
|
||||||
switchEvent: '监听切换事件',
|
switchEvent: '监听切换事件',
|
||||||
selectTip: '你切换到了',
|
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
badge: 'Show Badge',
|
badge: 'Show Badge',
|
||||||
@ -90,7 +89,6 @@ const i18n = {
|
|||||||
customColor: 'Custom Color',
|
customColor: 'Custom Color',
|
||||||
matchByName: 'Match by name',
|
matchByName: 'Match by name',
|
||||||
switchEvent: 'Change Event',
|
switchEvent: 'Change Event',
|
||||||
selectTip: 'You select ',
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user