SearchBox.js
910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// components/SearchBox/SearchBox.js
Component({
properties: {
placeholder: {
type: String,
value: '请输入搜索内容'
},
value: {
type: String,
value: ''
},
searchType: {
type: Number,
value: 1
},
inputAlign: {
type: String,
value: 'left' // 输入位置可配置: left, center, right
}
},
data: {},
methods: {
input(e) {
let { value } = e.detail;
this.setData({ value });
},
blur(e){
let { value } = this.data;
this.setData({ value });
},
clear() {
this.setData({ value: '' }, () => {
this.triggerEvent('search', '');
});
},
confirm(e) {
let { value } = e?.detail || {};
this.triggerEvent('search', value);
},
search(e) {
let { value } = e.currentTarget.dataset;
this.triggerEvent('search', value);
}
}
});