vueのinput入力ボックスのあいまいなクエリーの実装

1106 ワード

最近はvueを使ってwebappを書いていますが、少し面白い感じがします.
1:input入力ボックス:


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
  
転載先:https://www.cnblogs.com/sk-3/p/9047482.html