[TOC]
### 仿美團搜索框組件
~~~
<template>
<div class="header-search">
<!-- 搜索框 -->
<div class="search-wrap">
<el-input v-model="search"
@focus="onFoucs"
@blur="onBlur"
@input="onInput"
placeholder="請輸入內容" class="search-input"></el-input>
<el-button type="success" class="search-button"><i class="el-icon-search"></i></el-button>
</div>
<!-- 聚焦框 -->
<dl class="focus-wrapper" v-if="showHotWords">
<dt>熱門搜索</dt>
<dd v-for="(item, index) in hotWords" :key="index"><nuxt-link to="/2">{{item}}</nuxt-link></dd>
</dl>
<!-- 輸入關鍵詞框 -->
<dl class="key-words" v-if="showSearchList">
<dd v-for="(item, index) in focusData" :key="index"><nuxt-link to="/1">{{item}}</nuxt-link></dd>
</dl>
<!-- 熱門搜索 -->
<dl class="hot-keywords">
<dd v-for="(item,index) in searchData" :key="index"><nuxt-link to="/2">{{item}}</nuxt-link></dd>
</dl>
<!-- tag 標簽 -->
<dl class="search-tag">
<dd>美團外賣</dd>
<dd>貓眼電影</dd>
<dd>美團酒店</dd>
<dd>民宿/公寓</dd>
<dd>商家入駐</dd>
<dd>美團公益</dd>
</dl>
</div>
</template>
<script type="text/ecmascript-6">
export default {
data() {
return {
// 搜索關鍵詞
search: '',
// 獲取焦點狀態
isFocus: false,
// 熱門搜索
hotWords: ['北京動物園', '故宮博物院', '故宮', '北京歡樂谷', '八達嶺長城'],
// 聚焦框數據
focusData: ['火鍋','火鍋自助餐','火鍋','火鍋串串'],
// 搜索框數據
searchData: ['北京動物園','故宮博物院','故宮','北京歡樂谷','八達嶺長城','歡樂水魔方','水上樂園','十渡蹦極俱樂部']
}
},
computed: {
// 獲取焦點時,熱門搜索框出現,輸入關鍵詞 熱門搜索框隱藏
showHotWords() {
return this.isFocus && this.search.length === 0
},
// 獲取焦點時,輸入關鍵詞,熱門搜索隱藏,搜索列表顯示
showSearchList() {
return this.isFocus && this.search;
}
},
methods: {
// 獲取焦點
onFoucs() {
this.isFocus = true;
},
// 失去焦點
onBlur() {
setTimeout(() => {
this.isFocus = false;
}, 200)
},
// 監聽input事件
onInput() {
console.log('input')
}
}
}
</script>
<style lang="scss" scoped>
.header-search {
position: relative;
padding-left: 154px;
/* 搜索框樣式 */
.search-wrap {
display: flex;
.search-input {
width: 462px;
height: 40px;
/deep/ .el-input__inner {
border-top-right-radius: 0!important;
border-bottom-right-radius: 0!important;
border-right: none;
border-color: #13D1BE;
}
}
.search-button {
width: 88px;
height: 40px;
background: #13D1BE;
border-color: #13D1BE;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
/* 熱搜詞樣式 */
.hot-keywords {
padding: 10px 0;
display: flex;
dd {
padding: 0 6px;
a {
color: #999;
}
}
}
/* tag樣式 */
.search-tag {
padding-top: 30px;
color: #222;
display: flex;
dd {
font-weight: 700;
font-size: 16px;
margin-right: 20px;
cursor: pointer;
position: relative;
}
}
/* 聚焦框樣式 */
.focus-wrapper {
position: absolute;
z-index: 1000;
width: 462px;
box-sizing: border-box;
padding: 10px 10px;
background-color: #f8f8f8;
border: 1px solid #E5E5E5;
border-top: none;
box-shadow: 0 3px 5px 0 rgba(0,0,0,.1);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
dt {
margin-bottom: 10px;
}
dd {
display: inline-block;
margin-right: 10px;
line-height: 20px;
a {
color: #999;
&:hover {
color: #31BBAC;
}
}
}
}
/* 搜索關鍵詞樣式 */
.key-words {
position: absolute;
z-index: 1000;
width: 462px;
box-sizing: border-box;
padding: 10px 10px;
background-color: #f8f8f8;
border: 1px solid #E5E5E5;
border-top: none;
box-shadow: 0 3px 5px 0 rgba(0,0,0,.1);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
dd {
color: #999;
line-height: 30px;
a {
color: #333;
&:hover {
color: #31BBAC;
}
}
}
}
}
</style>
~~~
- 起步
- 環境搭建
- mock數據
- 基礎
- 生命周期
- 過濾器
- 過渡動畫
- keyframes動畫
- 動畫JS鉤子
- 路由
- 導航守衛
- 全局守衛
- 監聽器
- 自定義組件
- 獲取焦點
- mixins
- mixins抽離vuex
- 國際化
- 動態組件
- Dom
- 擴展
- 安裝devTools
- scss
- Nuxt引用多個UI庫
- vuex
- vuex命名空間
- vuex定義
- cli
- 安裝與卸載
- 環境變量
- 雜項
- Mock數據
- FeHelper
- git
- 反向代理
- 本地存儲
- stylus
- 常用mixins
- jsonp
- 配置
- mock配置
- 跨域配置
- 自定義路徑
- px2rem
- 代理后端請求
- 常用算法
- 字母排序城市數據
- 倒計時
- 通訊錄數據結構
- 請求
- axios防止多次請求
- 封裝axios請求
- axios使用
- 封裝axios
- 插件
- BetterScroll
- 高德定位
- polyfill
- fastClick
- LazyLoad
- storageCache
- moment
- keyFrameAnimation
- vueSwiper
- 組件
- Loading組件
- header組件
- 仿有道App導航
- SupportIcon
- 仿餓了么購物車跳動
- 購物車小球緩動
- 小球飛入購物車
- 仿音樂歌手列表
- 唱片飛入效果
- 搜索組件
- 仿美團PC搜索框
- 頁面布局
- stickyFooter
- 背景色漸變
- 背景虛化
- Ui組件
- CubeUi
- CreateApi
- tab滑屏切換
- 索引列表
- BScroll
- BScroll左右聯動導航
- vant
- 函數庫
- 常用Dom函數庫
- axios封裝
- 格式化音樂播放時長
- 搜索節流
- time格式化
- JS基礎
- window對象中的高度
- JS中的寬高
- 常用正則
- nuxt
- nuxtVuex
- 監聽頁面滾動
- 監聽body滾動
- 監聽局部滾動