element ui的input输入框组件有带输入建议的搜索框,但是实际项目中,不想要输入建议,直想要那个搜索功能,摸索了一下,最后把带输入建议的搜索框修改成了输入框+搜索。
如图实现这样一个动态输入搜索功能。
html部分:
<el-input
class="inline-input"
v-model="state1"
placeholder="请输入单据号"
>
</el-input>
<el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
<el-checkbox v-for="city in cities" :label="city" :key="city.id"><a :href=city.link target="_blank">{{city.biz_djbh}}</a>
</el-checkbox>
</el-checkbox-group>
js部分:
data() {
cities: '',
state1:'',
restaurants:''
},
method:{
//带输入建议input自带的方法
querySearch(queryString, cb) {
var restaurants = this.restaurants;
var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
console.log(results);
this.cities = results
},
},
//数据来源
getAll(){
var that = this;
let url = CONFIG.SERVERS.zhy_dbsrv
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
axios.get(url).then(function(response){
if(response.data.retCode == 1){
that.cities = response.data.list;
that.restaurants = response.data.list;
}
}).catch(function(error){
console.log(error)
})
},
watch:{
state1(){
this.querySearch(this.state1)
}
}
input输入框+搜索 完成!
注:restaurants 是所有数据,cities 是搜索出来的数据。