File tree 1 file changed +18
-27
lines changed
geekape-nav-main/components 1 file changed +18
-27
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div class =" app-search" >
3
- <el-select
4
- v-model =" value"
5
- filterable
6
- remote
7
- reserve-keyword
8
- placeholder =" 站内搜索"
9
- :remote-method =" remoteMethod"
10
- @change =" onChange"
11
- :loading =" loading" >
12
- <el-option
13
- v-for =" item in options"
14
- :key =" item.href"
15
- :label =" item.name"
16
- :value =" item.href" >
17
- </el-option >
18
- </el-select >
3
+ <el-autocomplete
4
+ v-model =" state"
5
+ :fetch-suggestions =" querySearchAsync"
6
+ placeholder =" 请输入内容"
7
+ @select =" handleSelect"
8
+ suffix-icon =" el-icon-search"
9
+ ></el-autocomplete >
19
10
</div >
20
11
</template >
21
12
@@ -27,25 +18,25 @@ export default {
27
18
name: " AppSearch" ,
28
19
data () {
29
20
return {
30
- options: [],
31
- value: ' ' ,
32
- list: [],
33
- loading: false ,
21
+ restaurants: [],
22
+ state: ' ' ,
23
+ timeout: null
34
24
}
35
25
},
36
26
methods: {
37
- async remoteMethod (query ) {
27
+ async querySearchAsync (query , cb ) {
38
28
if (query !== ' ' ) {
39
- this .loading = true ;
40
29
const res = await axios .get (API_NAV + ` ?keyword=${ query} ` )
41
- this .loading = false
42
- this .options = res? .data
30
+ if (Array .isArray (res .data )) {
31
+ res .data = res .data .map (item => (item .value = item .name , item))
32
+ cb (res .data )
33
+ }
43
34
} else {
44
- this . options = [];
35
+ cb ([])
45
36
}
46
37
},
47
- onChange ( url ) {
48
- window .open (url )
38
+ handleSelect ( item ) {
39
+ window .open (item . href )
49
40
}
50
41
}
51
42
}
You can’t perform that action at this time.
0 commit comments