Vue+Vant實現(xiàn)頂部搜索欄
更新時間:2021年06月07日 13:56:59 作者:在奮斗的大道
這篇文章主要為大家詳細介紹了Vue+Vant實現(xiàn)頂部搜索欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue+Vant實現(xiàn)頂部搜索欄的具體代碼,供大家參考,具體內(nèi)容如下
搜索欄組件源碼(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>
</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>
效果截圖:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
Vue3.3?+?TS4構建實現(xiàn)ElementPlus功能的組件庫示例
Vue.js?是目前最盛行的前端框架之一,而?TypeScript?則是一種靜態(tài)類型言語,它能夠讓開發(fā)人員在編寫代碼時愈加平安和高效,本文將引見如何運用?Vue.js?3.3?和?TypeScript?4?構建一個自主打造媲美?ElementPlus?的組件庫2023-10-10
Vue自定義el-table表格表頭高度的多種實現(xiàn)方法
在Vue項目中,使用Element?UI的el-table組件可以輕松創(chuàng)建功能豐富的表格,然而,默認情況下,el-table的表頭高度是固定的,本文將詳細介紹如何自定義el-table表頭的高度,提供多種實現(xiàn)方法,需要的朋友可以參考下2024-10-10
仿ElementUI實現(xiàn)一個Form表單的實現(xiàn)代碼
這篇文章主要介紹了仿ElementUI實現(xiàn)一個Form表單的實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-04-04
Vue JS對URL網(wǎng)址進行編碼解碼,轉換為對象方式
這篇文章主要介紹了Vue JS對URL網(wǎng)址進行編碼解碼,轉換為對象方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03

