Commit 56a02ffb authored by Damon's avatar Damon

perf: 搜索

parent 71f25dcf
...@@ -178,12 +178,13 @@ export default { ...@@ -178,12 +178,13 @@ export default {
search(val) { search(val) {
if (val){ if (val){
this.keyword = val this.keyword = val
let history = this.searchHistory let history = this.searchHistory.filter(v => v !== val)
history.unshift(val) history.unshift(val)
if (history.length > 9) { if (history.length > 9) {
history.splice(9, 1) history.splice(9, 1)
} }
this.$u.vuex('searchHistory', history) this.$u.vuex('searchHistory', history)
this.init()
} }
}, },
collection(item) { collection(item) {
......
...@@ -43,8 +43,7 @@ ...@@ -43,8 +43,7 @@
export default { export default {
data() { data() {
return { return {
keyword: '', keyword: ''
history: [],
} }
}, },
computed: { computed: {
...@@ -56,19 +55,20 @@ export default { ...@@ -56,19 +55,20 @@ export default {
deleteImg() { deleteImg() {
return process.uniEnv.qn_base_url + 'delete.png' return process.uniEnv.qn_base_url + 'delete.png'
}, },
}, history() {
created() { return this.searchHistory
this.history = this.searchHistory }
}, },
methods: { methods: {
search(val) { search(val) {
if (val){ if (val){
this.keyword = val this.keyword = val
this.history.unshift(val) let history = this.searchHistory.filter(v => v !== val)
if(this.history.length > 9){ history.unshift(val)
this.history.splice(9, 1) if(history.length > 9){
history.splice(9, 1)
} }
this.$u.vuex('searchHistory', this.history) this.$u.vuex('searchHistory', history)
this.toSearchDetail(val) this.toSearchDetail(val)
} }
}, },
...@@ -86,7 +86,6 @@ export default { ...@@ -86,7 +86,6 @@ export default {
content: '确认要清空搜索历史记录?', content: '确认要清空搜索历史记录?',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
this.history = []
this.$u.vuex('searchHistory', []) this.$u.vuex('searchHistory', [])
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment