1. 程式人生 > 程式設計 >Vue+Vant實現頂部搜尋欄

Vue+Vant實現頂部搜尋欄

本文例項為大家分享了vue+Vant實現頂部搜尋欄的具體程式碼,供大家參考,具體內容如下

搜尋欄元件原始碼(SearchBar.vue)

<template>
  <section class="city-search">
    <van-icon class="search-icon" name="search" />
    <input  placeholder="在此輸入檢索關鍵字" v-model="KeyWord">
    <van-icon class="clear-icon" name="clear" v-show="KeyWord" @click="clearSearchInput" />
  </section>
</templahttp://www.cppcns.com
te> <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 { marginiRkXQ
: 0 1.5vw; background-color: #F7F8FA; border: 0px; font-size: 14px; flex: 1 } .clear-icon { color: #999;} </style>

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

首頁引用搜索元件:

<template>
  <div>
      <search>&程式設計客棧lt;/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+Vant實現頂部搜尋欄

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。