1 <el-cascader 2 ref="cascaderDept" 3 @visible-change="changeBgClass" 4 @change="getDeptNodes" 5 :options="optionsDepartment"> 6 <el--cascader> 7 1.事件委托 8 addclick(){ 9 document.querySelectorAll("el-cascader-node"); 10 forEach(el=>{ 11 el.onclick=function(){ 12 if(this.firstElementChild){ 13 this.firstElementChild.click(); 14 } 15 } 16 }) 17 } 18 2.级联选择框(出现下拉框) 19 changeBgClass(val){ 20 if(val){ 21 this.addclick(); 22 } 23 } 24 3.点击最后一极收起下拉框 25 getDeptNodes(){ 26 this.addclick(); 27 if(this.$refs.cascaderDept&&this.$refs.cascaderDept.getCheckedNodes().length>0){ 28 let flag=this.$refs.cascaderDept.getCheckedNodes[0].data.leaf; 29 if(flag||(!this.$ref.cascaderDept.getCheckedNode()[0].hasChildren))
{this. $refs.cascaderDept.dropDownVisible=false;} 30 } 31 32 33 }