vue中Cascader 级联选择器实现-修改实现

vue 的cascader研究了好长时间,看了官网给的示例,上网查找了好多信息,才解决修改时回显的问题,现将方法总结如下:

vue代码:

<el-form-item label="芯片" prop="firmware">

<el-cascader

ref="cascader"

:options="firmwareTypeOptions"

v-model="form.firmware"

placeholder="请选择固件版本类型" style="width:100%"></el-cascader>

</el-form-item>

js:

data中:

// 父节点

firmwareTypeOptions:null,

firmwareMaps: {

value:null,

label: null,

children: null

}

---------------------------方法实现-------------------------

getDictsOne(){

getDicts(this.inverterFirmwareVersionType).then(response => {

// 定义数组

const nodes=[];

var arr=response.data;

for(let i = 0; i <arr.length; i++) {

let maps=[];

// 赋值

maps.value=arr[i].dictValue;

maps.label=arr[i].dictLabel;

// 网络模块子模块

if(parseInt(arr[i].dictValue)===1){

getDicts(this.inverterFirmwareNetworkModule).then(response => {

const nodess =response.data.map((i, index) => ({

value: i.dictValue,

label: i.dictLabel,

}));

maps.children=nodess;

});

}

// 主控模块子模块

if(parseInt(arr[i].dictValue)===2){

getDicts(this.inverterFirmwareMainModule).then(response => {

const nodess =response.data.map((i, index) => ({

value: i.dictValue,

label: i.dictLabel,

}));

maps.children=nodess;

});

}

nodes.push(maps);

}

this.firmwareTypeOptions=nodes;

});

}

效果:

相关推荐
Lotzinfly几秒前
10个JavaScript浏览器API奇淫技巧你需要掌握😏😏😏
前端·javascript·面试
liangshanbo121528 分钟前
React 19 新特性:原生支持在组件中渲染 <meta> 与 <link>
前端·javascript·react.js
金梦人生42 分钟前
Pinia 基本使用
vue.js
前端 贾公子1 小时前
《Vuejs设计与实现》第 18 章(同构渲染)(下)
前端·javascript·html
qq_402605651 小时前
python爬虫(二) ---- JS动态渲染数据抓取
javascript·爬虫·python
U.2 SSD2 小时前
ECharts 日历坐标示例
前端·javascript·echarts
2301_772093562 小时前
tuchuang_myfiles&&share文件列表_共享文件
大数据·前端·javascript·数据库·redis·分布式·缓存
Never_Satisfied2 小时前
在JavaScript / HTML中,词内断行
开发语言·javascript·html
追逐时光者2 小时前
找 Vue 后台管理系统模板看这个网站就够了!!!
vue.js
excel2 小时前
一文读懂 Vue 组件间通信机制(含 Vue2 / Vue3 区别)
前端·javascript·vue.js