docs(Search): use composition api

This commit is contained in:
chenjiahan 2020-12-06 17:05:55 +08:00
parent e5df5d734e
commit 56047bb655
3 changed files with 53 additions and 38 deletions

View File

@ -19,11 +19,12 @@ app.use(Search);
```
```js
import { ref } from 'vue';
export default {
data() {
return {
value: '',
};
setup() {
const value = ref('');
return { value };
},
};
```
@ -45,21 +46,23 @@ export default {
```
```js
import { ref } from 'vue';
import { Toast } from 'vant';
export default {
data() {
return {
value: '',
};
},
methods: {
onSearch(val) {
setup() {
const value = ref('');
const onSearch = (val) => {
Toast(val);
},
onCancel() {
};
const onCancel = () => {
Toast('Cancel');
},
};
return {
value,
onSearch,
onCancel,
};
},
};
```

View File

@ -25,11 +25,12 @@ app.use(Search);
```
```js
import { ref } from 'vue';
export default {
data() {
return {
value: '',
};
setup() {
const value = ref('');
return { value };
},
};
```
@ -51,21 +52,23 @@ Search 组件提供了 `search` 和 `cancel` 事件,`search` 事件在点击
```
```js
import { ref } from 'vue';
import { Toast } from 'vant';
export default {
data() {
return {
value: '',
};
},
methods: {
onSearch(val) {
setup() {
const value = ref('');
const onSearch = (val) => {
Toast(val);
},
onCancel() {
};
const onCancel = () => {
Toast('取消');
},
};
return {
value,
onSearch,
onCancel,
};
},
};
```

View File

@ -52,6 +52,10 @@
</template>
<script>
import { reactive, toRefs } from 'vue';
import { useTranslate } from '../../composables/use-translate';
import Toast from '../../toast';
export default {
i18n: {
'zh-CN': {
@ -74,25 +78,30 @@ export default {
},
},
data() {
return {
setup() {
const t = useTranslate();
const state = reactive({
value1: '',
value2: '',
value3: '',
value4: '',
value5: '',
value6: '',
});
const onSearch = (val) => {
Toast(val);
};
},
methods: {
onSearch(val) {
this.$toast(val);
},
const onCancel = () => {
Toast(t('cancel'));
};
onCancel() {
this.$toast(this.t('cancel'));
},
return {
...toRefs(state),
onSearch,
onCancel,
};
},
};
</script>