forked from opentiny/tiny-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclearable.vue
76 lines (72 loc) · 1.58 KB
/
clearable.vue
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<div class="demo-autocomplete">
<tiny-autocomplete
v-model="value"
clearable
placeholder="请输入内容"
:fetch-suggestions="querySearch"
name="myAutocomplete"
></tiny-autocomplete>
</div>
</template>
<script>
import { TinyAutocomplete } from '@opentiny/vue'
export default {
components: {
TinyAutocomplete
},
data() {
return {
restaurants: [],
value: ''
}
},
methods: {
querySearch(queryString, cb) {
let restaurants = this.restaurants
let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
// 调用 callback 返回建议列表的数据
cb(results)
},
createFilter(queryString) {
return (restaurant) => restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
},
loadAll() {
return [
{
value: 'GFD 科技 YX 公司',
address: '福州'
},
{
value: 'WWWW 科技 YX 公司',
address: '深圳福田区'
},
{
value: 'RFV 有限责任公司',
address: '中山市'
},
{
value: 'TGBYX 公司',
address: '梅州'
},
{
value: 'YHN 科技 YX 公司',
address: '韶关'
},
{
value: '康康物业 YX 公司',
address: '广州天河区'
}
]
}
},
mounted() {
this.restaurants = this.loadAll()
}
}
</script>
<style scoped>
.demo-autocomplete .tiny-autocomplete {
width: 270px;
}
</style>