• vue中input输入框的模糊查询实现


    最近在使用vue写webapp在,一些感觉比较有意思的分享一下。

    1:input输入框:

    <input class="s-search-text" placeholder="猜你喜欢我们" id="s-search-text" ref="searchval" v-model="message" @keyup="search">
    

    2:对input输入框的keyup事件进行处理,通过每输入一个字符触发一次keyup事件,来对接口进行数据请求。

    search () {
       let searchText = this.$refs.searchval.value
       if (searchText =='') {
           return
       } else {
           this.closeState = true
           this.searchState.showsug = true
           this.searchState.searchtext = this.$refs.searchval.value
           this.$emit('searchstate', this.searchState)
      }
      axios.get('http://localhost:3000/search/suggest?keywords=' + searchText, {}, {headers:{'Content-Type':'application/x-www-form-urlencoded'}})
          .then((res) => {
             if (res.data.code == 200) {
                 this.$emit('search', res.data.result.allMatch)
             }
          })
          .catch((err) => {
             console.log(err)
           })
       },
    

      github地址:https://github.com/xu-jinkai/vue-music

      

  • 相关阅读:
    Spring Boot
    Linux入门
    synchronized(一)
    避免XSS攻击
    MySql概述及入门(五)
    MySQL概述及入门(四)
    上传漏洞总结-upload-labs
    文件类型解析漏洞防御与攻击(PHP)
    Dvna for Owasp top 10 2017
    XSS 漏洞介绍
  • 原文地址:https://www.cnblogs.com/sk-3/p/9047482.html
Copyright © 2020-2023  润新知