效果图
代码点击文字即选中
在mounted里加这句话
mounted() {
// 点击文字即选中
this.timer = setInterval(function() {
document.querySelectorAll(".el-cascader-node__label").forEach(el => {
el.onclick = function() {
if (this.previousElementSibling) this.previousElementSibling.click();
};
});
}, 1000);
},
点击就收缩效果
标签上 加ref
<el-cascader
size='mini'
:options="goodsOptions"
v-model='goods_cid_list'
:props="{ checkStrictly: true,
value:'id',
label:'name',
children:'children'}"
clearable
@change='goodsOptionsChange'
ref="cascaderHandle"
:show-all-levels="false"
filterable></el-cascader>
goodsOptionsChange(e){
this.$refs.cascaderHandle.dropDownVisible = false; //监听值发生变化就关闭它
// 监听是否为最后一级,如果为最后一级,面板收起
var children = this.$refs.cascaderHandle.getCheckedNodes();
if(children[0].children.length < 1){ //判断有没有下级
this.$refs.cascaderHandle.dropDownVisible = false; //监听值发生变化就关闭它
}
},