我的目的:获取弹窗中级联下拉框,被选中的节点的数据。
实现过程:①级联事件@change:'事件名'
②处理获取到的节点的数据:getCascaderObj
③事件里调用getCascaderObj事件
直接上代码!!!:
①
<el-cascader
:props="{ checkStrictly: true }" // 是否有单选框,根据自己需求哦
style="width: 100%"
v-model="form.menuid" //绑定就不多说啦
:disabled="menuIndex ? true : false" // 是否禁用状态,根据自己需求哦
:options="catalogTreeDataOther" //级联下拉框的数据
@change="getIndex" // 级联的change事件,今天的重点!!!
></el-cascader>
②
//这个函数用于处理并且获取选中的节点
getCascaderObj(val, opt) {
return val.map(function (value, index, array) {
for (var item of opt) { // 可通过此处的item去获取选中节点中所需的数据哦
if (item.value == value) { //此处的item.value是指你数据的id,要记得修改哦,不然数据出不来的
opt = item.children;
return item;
}
}
return null;
});
},
③
//级联下拉框的change事件
getIndex(value) {
if (typeof value != "undefined") {
this.getCascaderObj(
this.form.menuid, // 传给getCascaderObj事件的参数1(当前级联绑定的属性)
this.catalogTreeDataOther // 传给getCascaderObj事件的参数2(当前级联的所有数据--即options的值)
); //选中节点数据
}
},
最后:祝我自己今天生日快乐~ ^^