溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Vue中如何用Vant實現(xiàn)頂部搜索欄

發(fā)布時間:2022-11-22 09:50:52 來源:億速云 閱讀:376 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Vue中如何用Vant實現(xiàn)頂部搜索欄的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇Vue中如何用Vant實現(xiàn)頂部搜索欄文章都會有所收獲,下面我們一起來看看吧。

搜索欄組件源碼(SearchBar.vue)

<template>
  <section class="city-search">
    <van-icon class="search-icon" name="search" />
    <input  placeholder="在此輸入檢索關(guān)鍵字" v-model="KeyWord">
    <van-icon class="clear-icon" name="clear" v-show="KeyWord" @click="clearSearchInput" />
  </section>
</template>
 
<script>
export default {
   data() {
        return {
            KeyWord: '',
        }
    },
    methods: {
        clearSearchInput() {
            this.KeyWord = '';
        }
    }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
    .city-search {
        background-color: #F7F8FA;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        height: 2.3rem;
        width: 94vw;
        margin: 2vw 4vw;
        border-radius: 8px;
    }
    .search-icon {
      margin-left: 5px;
    }
    input {
      margin: 0 1.5vw;
      background-color: #F7F8FA;
      border: 0px;
      font-size: 14px;
      flex: 1
    }
    .clear-icon { color: #999;}
  
</style>

其他組件依賴引用檢索組件

首頁引用搜索組件:

<template>
  <div>
      <search></search>
        首頁
  </div>
</template>
 
<script>
import Search from '@/components/SearchBar'
export default {
   name: "home",
   components: {
      'search': Search,
    },
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
 
</style>

vue是什么

Vue是一套用于構(gòu)建用戶界面的漸進(jìn)式JavaScript框架,Vue與其它大型框架的區(qū)別是,使用Vue可以自底向上逐層應(yīng)用,其核心庫只關(guān)注視圖層,方便與第三方庫和項目整合,且使用Vue可以采用單文件組件和Vue生態(tài)系統(tǒng)支持的庫開發(fā)復(fù)雜的單頁應(yīng)用。

關(guān)于“Vue中如何用Vant實現(xiàn)頂部搜索欄”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“Vue中如何用Vant實現(xiàn)頂部搜索欄”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI