feat(search): support model value

This commit is contained in:
rex 2020-05-01 22:25:44 +08:00
parent f2c4c02a37
commit f9b53aad99
2 changed files with 17 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp'; import { Weapp } from 'definitions/weapp';
import { canIUseModel } from '../common/version';
VantComponent({ VantComponent({
field: true, field: true,
@ -48,7 +49,9 @@ VantComponent({
methods: { methods: {
onChange(event: Weapp.Event) { onChange(event: Weapp.Event) {
this.setData({ value: event.detail }); if (canIUseModel()) {
this.setData({ value: event.detail });
}
this.$emit('change', event.detail); this.$emit('change', event.detail);
}, },
@ -58,26 +61,28 @@ VantComponent({
* https://github.com/youzan/@vant/weapp/issues/1768 * https://github.com/youzan/@vant/weapp/issues/1768
*/ */
setTimeout(() => { setTimeout(() => {
this.setData({ value: '' }); if (canIUseModel()) {
this.setData({ value: '' });
}
this.$emit('cancel'); this.$emit('cancel');
this.$emit('change', ''); this.$emit('change', '');
}, 200); }, 200);
}, },
onSearch() { onSearch(event) {
this.$emit('search', this.data.value); this.$emit('search', event.detail);
}, },
onFocus() { onFocus(event) {
this.$emit('focus'); this.$emit('focus', event.detail);
}, },
onBlur() { onBlur(event) {
this.$emit('blur'); this.$emit('blur', event.detail);
}, },
onClear() { onClear(event) {
this.$emit('clear'); this.$emit('clear', event.detail);
}, },
}, },
}); });

View File

@ -9,7 +9,8 @@
"baseUrl": ".", "baseUrl": ".",
"types": ["miniprogram-api-typings"], "types": ["miniprogram-api-typings"],
"paths": { "paths": {
"definitions/*": ["./packages/definitions/*"] "definitions/*": ["./packages/definitions/*"],
"packages/*": ["./packages/*"]
}, },
"skipLibCheck": true "skipLibCheck": true
}, },