The first is a pit, and 360 in the IE browser page refresh is executed again input event, no other browsers, so there will be a big problem, do lead full list is automatically displayed directly fill, refresh the page can not be hidden.
<input type="text" class="comHeaderBanSearchSearch fl" placeholder="请输入关键字查询" v-model="inputVal" @keyup.enter="searchBtn">
//在data中 我直接把inputVal的值拿到路由的值 这样页面一进来就不用走watch了 这样就避免了在created中赋值 是inputVal变化从而进行监听 还会走自动补全的函数了
data(){
return {
inputVal:this.$route.query.searchWord?this.$route.query.searchWord:'',
}
}
//监听 watch中
watch:{
inputVal(newVal,oldVal){
this.inputChange();
},
},
methods:{
/*自动补全数据 methods*/
inputChange() {
if(this.inputVal!=''){
getsuggestAPI({
term: this.inputVal,
num: 8
}).then(res => {
if (res.data.status) {
this.suggest = res.data.data;
this.issuggest=true;
this.$store.commit('suggest',this.issuggest)
}
})
}else{
this.suggest=[];
this.issuggest=false;
this.$store.commit('suggest',this.issuggest)
}
},
},