mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
Merge pull request #3106 from rex-zsd/feat/search_20200501
feat(Search): support model value
This commit is contained in:
commit
b416401288
@ -1,18 +1,16 @@
|
|||||||
<demo-block title="基本用法">
|
<demo-block title="基本用法">
|
||||||
<van-search
|
<van-search
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
bind:change="onChange"
|
|
||||||
bind:search="onSearch"
|
bind:search="onSearch"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block title="事件监听">
|
<demo-block title="事件监听">
|
||||||
<van-search
|
<van-search
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
show-action
|
show-action
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
bind:change="onChange"
|
|
||||||
bind:search="onSearch"
|
bind:search="onSearch"
|
||||||
bind:cancel="onCancel"
|
bind:cancel="onCancel"
|
||||||
bind:clear="onClear"
|
bind:clear="onClear"
|
||||||
@ -21,7 +19,7 @@
|
|||||||
|
|
||||||
<demo-block title="搜索框内容对齐">
|
<demo-block title="搜索框内容对齐">
|
||||||
<van-search
|
<van-search
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
input-align="center"
|
input-align="center"
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
/>
|
/>
|
||||||
@ -30,14 +28,14 @@
|
|||||||
<demo-block title="禁用搜索框">
|
<demo-block title="禁用搜索框">
|
||||||
<van-search
|
<van-search
|
||||||
disabled
|
disabled
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block title="自定义背景色">
|
<demo-block title="自定义背景色">
|
||||||
<van-search
|
<van-search
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
shape="round"
|
shape="round"
|
||||||
background="#4fc08d"
|
background="#4fc08d"
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
@ -46,12 +44,11 @@
|
|||||||
|
|
||||||
<demo-block title="自定义按钮">
|
<demo-block title="自定义按钮">
|
||||||
<van-search
|
<van-search
|
||||||
value="{{ value }}"
|
model:value="{{ value }}"
|
||||||
label="地址"
|
label="地址"
|
||||||
shape="round"
|
shape="round"
|
||||||
placeholder="请输入搜索关键词"
|
placeholder="请输入搜索关键词"
|
||||||
use-action-slot
|
use-action-slot
|
||||||
bind:change="onChange"
|
|
||||||
bind:search="onSearch"
|
bind:search="onSearch"
|
||||||
>
|
>
|
||||||
<view slot="action" bind:tap="onClick">搜索</view>
|
<view slot="action" bind:tap="onClick">搜索</view>
|
||||||
|
@ -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) {
|
||||||
|
if (canIUseModel()) {
|
||||||
this.setData({ value: event.detail });
|
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(() => {
|
||||||
|
if (canIUseModel()) {
|
||||||
this.setData({ value: '' });
|
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -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
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user