El-Tree 扩展 父级选中可以影响子级,子级不能影响父级

关键代码

check-strictly // 在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false

加上check-strictly属性之后父子级将不会互相影响,再通过checkChange方法去遍历子级

template

<el-tree

              check-strictly

              :data="menuList"

              :props="{ label: 'name', children: 'children' }"

              node-key="id"

              ref="listTree"

              accordion

              show-checkbox

              @check-change="checkChange"

            >

            </el-tree>

js

checkChange (a, b, c) {

      this.findChildren(a, b, c)

    },

    findChildren (current, b, c) {

      this.$refs.listTree.setChecked(current.id, b, c)

      const d = current.children

      if (d.length > 0) {

        d.forEach(a => {

          this.findChildren(a, b, c)

        })

      }

    },

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容