Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Add search function in searchbar
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoandy107 committed Jan 13, 2019
1 parent 492cf9c commit 933a246
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions components/index/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"uid": "yGk4p9RPWkgT56IBeYnAro1IJeU2",
"apiKey": "AIzaSyDlcf8iUDzlJ9mVEiCR8tLR51pD1HeUqvs"
}
16 changes: 4 additions & 12 deletions components/public/header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@
:span="8"
class="search"
>
<el-autocomplete
v-model="value"
:fetch-suggestions="querySearchAsync"
placeholder="請輸入內容"
@select="handleSelect"
>
<el-button
slot="append"
icon="el-icon-search"
/>
</el-autocomplete>
<search-bar/>
</el-col>
<el-col :span="8">
<v-layout>
Expand All @@ -54,11 +44,13 @@
import Navbar from './nav.vue'
import User from './user.vue'
import Cart from './cart.vue'
import SearchBar from './search.vue'
export default {
components: {
Navbar,
User,
Cart
Cart,
SearchBar
},
props: {
prominent: {
Expand Down
30 changes: 28 additions & 2 deletions components/public/header/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
v-model="value"
:fetch-suggestions="querySearchAsync"
placeholder="請輸入內容"
@select="handleSelect"
>
<el-button
slot="append"
Expand All @@ -16,6 +15,33 @@
</div>
</template>

<style lang="scss">
<script>
export default {
data() {
return {
value: '',
timeout: null
}
},
methods: {
async querySearchAsync(queryString, callback) {
let { data } = await this.$axios.get(`/goods?keyword=${queryString}`)
console.log(data)
let searchResult = []
data.forEach(element => {
searchResult.push({
value: element.name
})
})
console.log(searchResult)
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
callback(searchResult)
}, 2000 * Math.random())
}
}
}
</script>

<style lang="scss">
</style>
Binary file added mysql/ibtmp1
Binary file not shown.

0 comments on commit 933a246

Please sign in to comment.