el-autocomplete 的使用
程序员文章站
2022-05-10 19:05:26
...
<el-form-item label="项目选择" prop="projectReimbursement.projectId" :verify="['NotNull']">
<el-autocomplete
clearable
class="inline-input"
v-model="detailForm.projectReimbursement.projectName"
:fetch-suggestions="querySearch"
value-key="projectName"
placeholder="请输入项目"
@select="handleSelect"
></el-autocomplete>
</el-form-item>
querySearch(queryString, cb) {
var restaurants = this.projectOptions;
var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
// 调用 callback 返回建议列表的数据
cb(results);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.projectName.indexOf(queryString.toLowerCase()) === 0);
};
},
handleSelect(item) {
this.detailForm.projectReimbursement.projectId = item.id;
console.log(item);
},
value-key=“projectName” 输入建议对象中用于显示的键名
return (restaurant.projectName.indexOf(queryString.toLowerCase()) === 0); 用来比对的值,符合条件的筛选出来
@select=“handleSelect” 当前选中的那一项 可在事件里进行操作 获取当前项的id等