欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Vue el-autocomplete 實(shí)現(xiàn)類似百度搜索框功能

 更新時(shí)間:2019年10月25日 11:26:33   作者:xu_song  
本文通過代碼給大家介紹了Vue el-autocomplete 實(shí)現(xiàn)類似百度搜索框功能,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

效果圖如下所示:

首先上代碼

<template>
  <div class="assets-search height-all">
    <div class="search-layout">
      <div class="search-title">讓數(shù)據(jù)觸手可及</div>
      <div class="search-input-layout">
        <!--<el-input class="search-input" placeholder="檢索數(shù)據(jù)"
             @keyup.enter.native="searchAssets($event)"
             v-model="searchContent">
          <el-button style="color: white"
                @click="searchAssets(searchContent)"
                slot="append">搜 索</el-button>
        </el-input>-->
        <el-autocomplete
          class="inline-input search-input"
          v-model="searchContent"
          ref="autocomplete"
          :fetch-suggestions="requestDoSuggest"
          placeholder="請(qǐng)輸入您需要檢索資源名稱或者中文"
          @keyup.enter.native="searchAssets($event)"
          :trigger-on-focus="false"
          @select="handleSelect"
        >
          <el-button @click="searchAssets" slot="append">搜 索</el-button>
        </el-autocomplete>
        <div class="search-word-layout" v-show="searchWordList.length">
          <span class="search-word-title">熱門搜索:</span>
          <div class="search-word-list">
            <span class="search-word"
                v-for="(item, index) in searchWordList"
                @click="clickHotWord(item)"
                :key="index">{{item}}</span>
          </div>
        </div>
      </div>
      <el-button v-if="false" class="db-number-layout">{{`資產(chǎn)庫:${ddNumber}`}}</el-button>
    </div>
  </div>
</template>
<script>
  import {mapActions } from 'vuex';
  export default {
    name: "search",
    created() {
      this.requestHotWord();
    },
    data() {
      return {
        searchContent:'',
        ddNumber:3445,
        searchWordList:[],
        hotWordSize:5,
      }
    },
    methods:{
      ...mapActions(['_AJAX']),
      /**
       * 點(diǎn)擊熱詞搜索
       */
      clickHotWord(item) {
        this.searchContent = item;
        this.searchAssets();
      },
      /**
       * 跳轉(zhuǎn)到搜索結(jié)果頁面
       */
      searchAssets(event) {
        if (event) {
          event.target.blur();
          this.$refs.autocomplete.close();
        }
        let viewRoute = this.$router.resolve({
          path: '/assets/searchResult',
          query: {
            searchContent: this.searchContent,
          }
        });
        window.open(viewRoute.href, '_blank');
      },
      /**
       * 自動(dòng)補(bǔ)全
       */
      requestDoSuggest(queryString, cb) {
        let params = {
          url: 'esSearch.doSuggest',
          data: {
            input: queryString,
            size:4,
          },
          method: 'GET'
        };
        this._AJAX(params)
          .then(res => {
            let list = res.result.map((item)=>{
              return {value:item}
            })
            cb(list);
          })
      },
      /**
       * 選擇聯(lián)想出來的數(shù)據(jù)
       */
      handleSelect(item) {
        this.searchContent = item.value;
        this.searchAssets();
      },
      /**
       * 請(qǐng)求熱詞列表
       */
      requestHotWord() {
        let params = {
          url: 'esSearch.queryHotWord',
          data: {
            size:this.hotWordSize,
          },
          method: 'GET'
        };
        this._AJAX(params)
          .then(res => {
            this.searchWordList = res.result;
          })
      }
    },
  }
</script>
<style lang="scss">
  .assets-search {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #6ba9ec;
    .search-layout{
      text-align: center;
      .search-title{
        font-size: 50px;
        color: white;
        font-weight: bold;
        padding-bottom: 40px;
      }
      .search-input-layout{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .search-input{
          width: 50%;
        }
        .search-word-layout{
          text-align: left;
          width: 50%;
          padding: 15px;
          display: flex;
          flex-direction: row;
          align-items: center;
          .search-word-title{
            font-size: 15px;
            color: white;
          }
          .search-word-list{
            span:hover{
              color: #666666;
            }
          }
          .search-word{
            font-size: 15px;
            color: white;
            padding-right: 10px;
            cursor: pointer;
          }
        }
      }
      .db-number-layout{
        margin-top: 80px;
      }
    }
    .el-input-group--append .el-input__inner {
      border-radius: 0;
      height: 48px;
      line-height: 48px;
    }
    .el-input-group__append {
      background: $color-assist;
      border-color: $color-assist;
      border-radius: 0;
      color: white;
    }
  }
</style>

注意的細(xì)節(jié)

基礎(chǔ)使用

fetch-suggestions 這個(gè)方法是去請(qǐng)求包含關(guān)鍵字的搜索功能,這里注意返回結(jié)果里面的列表對(duì)象屬性里面要有一個(gè)value的屬性,這個(gè)才能顯示,聯(lián)想輸入內(nèi)容。

select 方法是選擇了一個(gè)聯(lián)想輸入的具體數(shù)據(jù)的點(diǎn)擊事件

注意事項(xiàng)

按enter鍵進(jìn)行搜索功能@keyup.enter.native="searchAssets(event)",有些人會(huì)好奇,這個(gè) event)",有些人會(huì)好奇,這個(gè)event)",有些人會(huì)好奇,這個(gè)event是一個(gè)什么東西,其實(shí)就是一個(gè)事件,代碼

if (event) {
   event.target.blur();
   this.$refs.autocomplete.close();
}

這個(gè)是為了處理點(diǎn)擊enter使input輸入框失去焦點(diǎn),還有一個(gè)作用就是,讓el-autocomplete 的聯(lián)想輸入框關(guān)閉。這個(gè)達(dá)到和百度搜索類似的效果。

總結(jié)

以上所述是小編給大家介紹的基于Vue el-autocomplete 實(shí)現(xiàn)類似百度搜索框功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • flv.js在vue中的使用方法

    flv.js在vue中的使用方法

    flv.js是一個(gè)用于在瀏覽器中解碼和播放FLV視頻的JavaScript庫,它可以將FLV視頻流解碼并顯示在HTML5的video元素中,從而實(shí)現(xiàn)在瀏覽器中直接播放FLV格式的視頻文件,本文給大家介紹flv.js在vue中的使用,感興趣的朋友一起看看吧
    2023-11-11
  • Vue?中?Promise?的then方法異步使用及async/await?異步使用總結(jié)

    Vue?中?Promise?的then方法異步使用及async/await?異步使用總結(jié)

    then?方法是?Promise?中?處理的是異步調(diào)用,異步調(diào)用是非阻塞式的,在調(diào)用的時(shí)候并不知道它什么時(shí)候結(jié)束,也就不會(huì)等到他返回一個(gè)有效數(shù)據(jù)之后再進(jìn)行下一步處理,這篇文章主要介紹了Vue?中?Promise?的then方法異步使用及async/await?異步使用總結(jié),需要的朋友可以參考下
    2023-01-01
  • 一文詳解Vue響應(yīng)式數(shù)據(jù)的原理

    一文詳解Vue響應(yīng)式數(shù)據(jù)的原理

    在vue2的響應(yīng)式中,存在著添加屬性、刪除屬性、以及通過下標(biāo)修改數(shù)組,但頁面不會(huì)自動(dòng)更新的問題,而這些問題在vue3中都得以解決,本文就給大家詳細(xì)的介紹一下Vue響應(yīng)式數(shù)據(jù)原理,感興趣的小伙伴跟著小編一起來看看吧
    2023-08-08
  • 如何通過URL來實(shí)現(xiàn)在Vue中存儲(chǔ)業(yè)務(wù)狀態(tài)實(shí)用技巧

    如何通過URL來實(shí)現(xiàn)在Vue中存儲(chǔ)業(yè)務(wù)狀態(tài)實(shí)用技巧

    這篇文章主要為大家介紹了如何通過URL來實(shí)現(xiàn)在Vue中存儲(chǔ)業(yè)務(wù)狀態(tài)實(shí)用技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式

    vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式

    這篇文章主要介紹了vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 程序員應(yīng)該知道的vuex冷門小技巧(超好用)

    程序員應(yīng)該知道的vuex冷門小技巧(超好用)

    Vue基本用法很容易上手,但是有很多優(yōu)化的寫法你就不一定知道了,下面這篇文章主要給大家介紹了關(guān)于程序員應(yīng)該知道的vuex冷門小技巧的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • Vue實(shí)現(xiàn)剪切板圖片壓縮功能

    Vue實(shí)現(xiàn)剪切板圖片壓縮功能

    這篇文章主要介紹了Vue實(shí)現(xiàn)剪切板圖片壓縮功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • vue實(shí)現(xiàn)iview表格添加篩選功能的示例代碼

    vue實(shí)現(xiàn)iview表格添加篩選功能的示例代碼

    本文主要介紹了vue實(shí)現(xiàn)iview表格添加篩選功能的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • Element-ui中元素滾動(dòng)時(shí)el-option超出元素區(qū)域的問題

    Element-ui中元素滾動(dòng)時(shí)el-option超出元素區(qū)域的問題

    這篇文章主要介紹了Element-ui中元素滾動(dòng)時(shí)el-option超出元素區(qū)域的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-05-05
  • Vue實(shí)現(xiàn)步驟條效果

    Vue實(shí)現(xiàn)步驟條效果

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)步驟條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評(píng)論