业务需求:点击左侧树,右边点击上传按钮后弹出页面默认选中左侧选中的节点
步骤:1、定义数组 parentList:[];
2、点击左侧时,获取选中节点及所有父节点,赋值给parentList;
<el-tree :data="picOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" default-expand-all highlight-current @node-click="handleNodeClick" />
js
// 节点单击事件 handleNodeClick(data,node) { this.parentList = []; let a; a = { tradeId:data.id, } this.handleQueryTree(a); this.platform(node); }, platform(node) { if (!node.parent) {// 若无父节点,则直接返回 return } this.parentList.unshift(node.data.id)// 将value保存起来 //调用递归 this.platform(node.parent); }
2、点击右侧新增按钮时,赋值给标签元素
<el-cascader :options="picOptions" :show-all-levels="true" :props="{value:'id'}" v-model="form.pictureType"></el-cascader>
js,赋值
uploadCli(){ this.reset(); this.upload.open = true; this.form.pictureType = this.parentList; },
标签:node,el,parentList,platform,选中,cascader,默认值,data,节点 From: https://www.cnblogs.com/person008/p/16775945.html