您现在的位置是:网站首页> 编程资料编程资料
Vue动态数据实现 el-select 多级联动、数据回显方式_vue.js_
2023-05-24
254人已围观
简介 Vue动态数据实现 el-select 多级联动、数据回显方式_vue.js_
动态数据 el-select 多级联动、数据回显

父组件
import ProviderCategory from './ProviderCategory'
子组件
changeSelectData(value, idx )" value-key="id" >
//测试模拟数据 childNodes = [ { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "上衣", id:2, pId: 1, sort: 1, childNodes: [ { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "短袖", haveGoods: true, id: 5, pId: 2, sort: 1, childNodes:[ { id:111, pId: 5, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "短袖裤子", childNodes: [] }, { id:122, pId: 5, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "短袖鞋子", childNodes: [] } ], }, { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "西装", haveGoods: false, id: 6, pId: 2, sort: 1, childNodes:[ { id:112, pId: 6, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "西装裤子", childNodes: [] }, { id:121, pId: 6, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "西装鞋子", childNodes: [] } ], } ] }, { id:11, pId: 1, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "裤子", childNodes: [ { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "牛仔", haveGoods: true, id: 112222, pId: 11, sort: 1, childNodes:[], }, ] }, { id:12, pId: 1, sort: 1, categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "鞋子", childNodes: [ { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "耐克", haveGoods: true, id: 1121, pId: 12, sort: 1, childNodes:[ { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "西牛仔", haveGoods: true, id: 11211, pId: 1121, sort: 1, childNodes:[], }, ], }, { categoryImg: "https://www.baidu.com/img/bd_logo1.png", categoryName: "阿迪", haveGoods: true, id: 1122, pId: 12, sort: 1, childNodes:[], }, ] } ]; //数据回显 findId(arr, id) { //将选中的数组和id组成一个数组 for (let i = 0; i < arr.length; i++) { if (arr[i].id === id) { return [ [arr, i] ] break } } let c = [] arr.forEach((item, i) => { let r = this.findId(item.childNodes || [], id) if (r && r.length) { c = [ [arr, i] ].concat(r) } }) // console.log(c,"回显数据") return c },多级联动select菜单(易懂)
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- JS中ESModule和commonjs介绍及使用区别_javascript技巧_
- Vue3+Canvas实现简易的贪吃蛇游戏_vue.js_
- JS SVG获取验证码的玩法示例_JavaScript_
- JavaScript利用normalizr实现复杂数据转换_javascript技巧_
- node+js搭建时间服务器的思路详解_node.js_
- 一文教你学会在Vue3中自定义指令_vue.js_
- JS递归遍历查询是否有权限示例详解_JavaScript_
- JavaScript三大重点同步异步与作用域和闭包及原型和原型链详解_javascript技巧_
- 浅析JavaScript对象转换成原始值_javascript技巧_
- Vue组件实现景深卡片轮播示例_vue.js_
