mpvue-search-page
Version:
This is mpvue model about searchPage
63 lines (49 loc) • 1.38 kB
JavaScript
export default {
clearInput(event) {
this.searchInput = "";
},
cancelSearch() {
this.searchInput = "";
this.$emit('closePage', false);
this.$emit('bindSearch', this.searchInput);
},
bindConfirm(event) {
const searchText = event.target.value;
this.__unshiftArray(searchText);
this.$emit('bindSearch', event.target.value);
},
clearSearchSource() {
this.historySource = [];
wx.setStorageSync('historySource', '');
},
historySearch(content) {
this.searchInput = content;
this.$emit('bindSearch', content);
},
// -------------------------私有函数 Star -------------------------
__unshiftArray(val) {
val = val.trim();
if (!val) return;
if (this.historySource.includes(val)) return;
if (this.historySource.length > this.maxArray) {
this.historySource.pop();
}
if (!this.historySource) {
this.historySource = [];
}
this.historySource.unshift(val);
wx.setStorageSync('historySource', this.historySource);
}
// -------------------------私有函数 End --------------------------
// 重构搜索组件
// CONST HISTORY_KEY = 'historySource';
// getHistory(){
// if(wx.getStorageSync(HISTORY_KEY)){
// return [];
// }
// return wx.getStorageSync(HISTORY_KEY);
// },
// addToHistory(val){
// this.__unshiftArray(val);
// }
}