把选择器给组件化出来,数据是远程加载的,设置了清空功能,但是第一次点击清空后,选择器会变成另外一个值,再次点击清空后才会真正清空;且这种情况是在有些选项中出现,有些选项则不会需要二次点击情况
<template>
<el-select filterable ref="comp" v-model="localCompName" @change="compCodeChange" clearable :filter-method="getCompDropDown" @visible-change="visibleChange" placeholder="请选择" size="small">
<el-option
v-for="item in compDropDownOptions"
:key="item.compName"
:label="item.compName"
:value="item.keyCode" style="width: 440px;">
<el-row>
<el-col :span="6">
<span style="color: #8492a6; font-size: 13px">{{ item.keyCode }}</span>
</el-col>
<el-col :span="18">
<span>{{ item.compName }}</span>
</el-col>
</el-row>
</el-option>
<el-pagination
small
:total="dropDownTotal"
:current-page.sync="compDropDownQueryParams.pageNum"
:page-size="compDropDownQueryParams.pageSize"
@current-change="getCompDropDown()"
@prev-click="getCompDropDown()"
@next-click="getCompDropDown()"
/>
</el-select>
</template>
compCodeChange(val){
this.$emit('getCompCode', val)
this.$emit('getCompName', this.$refs.comp.hoverOption.currentLabel)
this.$forceUpdate();
},
//下拉方法,失去或获得焦点时对文本框进行校验
getCompDropDown(val){
this.compDropDownQueryParams.compName = val;
getCompDropDown(this.compDropDownQueryParams).then(response => {
this.compDropDownOptions = response.rows;
this.dropDownTotal = response.total;
});
},
visibleChange(val){
if(val){
this.getCompDropDown(this.localCompName);
}else{
if(this.localCompName == null){
this.localCompName = null;
this.localCompCode = null;
}
}
this.$forceUpdate();
},
已经试过强刷了,没有效果(也可能我用的地方不对);
本来想把clearable写成一个函数再返回true看看,结果报错说clearable必须是boolean不能是function,没法试…