search.vue
1.16 KB
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
46
47
48
<template>
<div :class="prefixCls">
<i-input
v-model="currentQuery"
size="small"
:icon="icon"
:placeholder="placeholder"
@on-click="handleClick"></i-input>
</div>
</template>
<script>
import iInput from '../input/input.vue';
export default {
name: 'Search',
components: { iInput },
props: {
prefixCls: String,
placeholder: String,
query: String
},
data () {
return {
currentQuery: this.query
};
},
watch: {
query (val) {
this.currentQuery = val;
},
currentQuery (val) {
this.$emit('on-query-change', val);
}
},
computed: {
icon () {
return this.query === '' ? 'ios-search' : 'ios-close-circle';
}
},
methods: {
handleClick () {
if (this.currentQuery === '') return;
this.currentQuery = '';
this.$emit('on-query-clear');
}
}
};
</script>