input输入框的input事件

首先是一个坑,在IE和360浏览器中页面刷新会执行一遍input事件,在其他浏览器就没有,所以会有很大问题,导致做的自动补全列表直接显示,刷新页面也不能隐藏。

<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)
        }


      },
},



 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值