先定义变量保存:placeSearch 如下:
return {
form: {},
query: {},
loading: true,
page: {
pageSize: 10,
currentPage: 1,
total: 0
},
placeSearch: '',
selectionList: [],
在提交搜索时,保存当前的关键字,如下:
onLoad(page, params = {}) {
this.loading = true;
///保存当前变量 this.placeSearch=params.placeSearch;
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.loading = false;
this.selectionClear();
});
},
在column里,定义为html:true, 然后把关键字代替,如下所示:
{
label: "暂住地派出所",
prop: "zanzhudipaichusuo",
//search: true,
html:true,
formatter:(val)=>{
if(this.placeSearch!=''){
//console.log(this.placeSearch);
return val.zanzhudipaichusuo.replace(this.placeSearch, '<font color="red">' + this.placeSearch + '</font>')
}else{
return val.zanzhudipaichusuo
}
},
rules: [{
required: false,
message: "请输入暂住地派出所",
trigger: "blur"
}]
},