Skip to content

Commit 7e758a8

Browse files
author
zhongchubing
committed
refactor: 前台站内搜索
1 parent 8867b25 commit 7e758a8

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

geekape-nav-main/components/AppSearch.vue

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
<template>
22
<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>
1910
</div>
2011
</template>
2112

@@ -27,25 +18,25 @@ export default {
2718
name: "AppSearch",
2819
data() {
2920
return {
30-
options: [],
31-
value: '',
32-
list: [],
33-
loading: false,
21+
restaurants: [],
22+
state: '',
23+
timeout: null
3424
}
3525
},
3626
methods: {
37-
async remoteMethod(query) {
27+
async querySearchAsync(query, cb) {
3828
if (query !== '') {
39-
this.loading = true;
4029
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+
}
4334
} else {
44-
this.options = [];
35+
cb([])
4536
}
4637
},
47-
onChange(url) {
48-
window.open(url)
38+
handleSelect(item) {
39+
window.open(item.href)
4940
}
5041
}
5142
}

0 commit comments

Comments
 (0)