用value绑定输入的值,要通过@input事件监听,这个方法只要input值发生改变就会调用,v-if控制‘清空’这个图标,没值就不显示,我悟了!!!
效果图
<view slot="default" class="search_box">
<text class="icon_search"></text>
<input style="width: 280px;" :value="searchName" class="prompt" placeholder="请输入员工姓名" @input="theBlur"></input>
<text v-if="searchName" class="icon_close" @click="close"></text>
</view>
<sript>
//methods
close:function(){
this.searchName = ''
this.queryByInput()
},
theBlur(e){
console.log(e.target.value)
this.searchName = e.target.value
this.queryByInput()//查询列表调用的方法
}
<sript>
<style>
.search_box {
width: 400upx;
height: 64upx;
background-color: #f5f5f5;
border-radius: 32upx;
display: flex;
align-items: center;
padding: 0upx 40upx;
.prompt {
font-size: 28upx;
color: #cccccc;
}
}
.icon_search {
background-image: url(../../static/nav/map_ic_search.png);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
width: 32upx;
height: 28upx;
margin-right: 20upx;
}
.icon_close {
background-image: url(../../static/nav/del.png);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
width: 32upx;
height: 28upx;
margin-right: 10upx;
}
</style>