搜索页面
搜索栏基本布局
在搜索页serch/main.less导入样式文件
.search {
padding: 20rpx;
background: #eee;
.search-content {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
position: relative;
.search-input {
height: 60rpx;
line-height: 60rpx;
background: #fff;
padding: 0 20rpx;
flex: 1;
display: flex;
align-items: center;
icon {
margin-right: 10rpx;
display: block;
width: 16px;
height: 16px;
}
input {
flex: 1;
font-size: 15px;
}
}
.cancel {
height: 60rpx;
line-height: 60rpx;
margin-left: 10rpx;
}
.search-modal {
position: absolute;
width: 100%;
left: 0;
top: 60rpx;
/* background: #f5f5f5; */
/* padding: 20rpx; */
overflow-y: auto;
.search-item {
height: 60rpx;
line-height: 60rpx;
border-bottom: 1px #eee solid;
font-size: 15px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
}
.history {
display: flex;
justify-content: space-between;
padding: 20rpx;
}
.history-list {
display: flex;
padding: 20rpx 10rpx;
flex-wrap: wrap;
.history-item {
margin: 10rpx 10rpx;
padding: 20rpx;
background: #eee;
}
}
在serch/index.vue中进行导入样式
<style scoped lang="less">
@import './main.less';
</style>
搭建布局:
第一步:搜索页基本布局
展示效果
第二步:给搜索框增加图标和提示语
展示效果
第三步:取消按钮,默认不显示;当输入字时,取消按钮显示
结构
<template>
<div>
<!-- 顶部搜索栏 -->
<div class="search">
<div class="search-content">
<!-- 输入框 -->
<div class="search-input">
<icon type='search' size='16'/>
<!-- v-model='keyword' 绑定输入字 -->
<input @input='queryData' v-model='keyword' placeholder="请输入关键字" />
</div>
<!-- 取消按钮 -->
<button class="cancel" v-if='keyword' @click='handleCancel'>取消</button>
</div>
</div>
</div>
</template>
<script>
export default {
data () {
return {
// 搜索关键字
keyword: '',
}
},
methods: {
handleCancel () {
// 取消搜索
this.keyword = ''
}
}
}
</script>
<style scoped lang="less">
@import './main.less';
</style>
输入文字,显示取消按钮; 点击取消按钮,隐藏取消按钮