2020-09-15

最近做后台管理系统做权限管理,用的是tree树形结构,当然文档提供了关联关系 但是不是我想要的
需求是这样的:
当选中父节点时下面所有子节点选中;当选中子节点时,它的父节点选中;
当取消子节点选中时,它的父级不变

下面展示一些 内联代码片

// template
<el-tree
      ref="tree"
      default-expand-all
      :data="optionData"
      show-checkbox
      check-strictly
      node-key="id"
      @check="getCurrentNode"
      :default-checked-keys="ruleForm.menuIds"
      :props="defaultProps">
</el-tree>
// js

        data(){

            return{

                modal_menu:false,

                roleIds:'',

                systemType:'lcc',

                roleTypes:'',

                defaultProps: {

                    children: 'children',

                    label: 'title'

                },

                ruleForm: []

            }

        },

        computed:{

            tree_menu_permission(){

                let data = this.$store.state.role.tree_menu_permission;

                if(data.length) {

                    this.checkedShow(data);

                }

                return this.$store.state.role.tree_menu_permission;

            }

        },

methods:{
    getCurrentNode(data) {
       // console.log(data)
        let node = this.$refs.tree.getNode(data);
        this.childNodes(node);
        this.parentNodes(node);
     },
     //具体方法可以看element官网api
     childNodes(node){
         let len = node.childNodes.length;
          for(let i = 0; i < len; i++){
              node.childNodes[i].checked = node.checked;
              this.childNodes(node.childNodes[i]);
          }
      },
      parentNodes(node){
          if(node.parent){
              for(let key in node){
                  if(key == "parent"){
                      node[key].checked = true;
                      this.parentNodes(node[key]);
                  }
              }
          }
      },
}
//希望对童鞋们有所帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值