ElementUI

tree 仅允许勾选同一个层级的数据

2021-07-26  本文已影响0人  你好岁月神偷

<el-tree

    class="filter-tree"

    :data="data"

    node-key="id"

    :props="defaultProps"

    :check-strictly='true'

    default-expand-all

    show-checkbox

    @check-change="handleCheckChange"

    ref="tree">

</el-tree>

核心代码:
handleCheckChange(data, checked, indeterminate) {

            this.$nextTick(() => {

                if(checked) {

                    let nodes = this.$refs.tree.getCheckedNodes();

                    if(nodes.length == 0) {

                        this.pid = ''

                    } else if(nodes.length == 1) {

                        this.pid = nodes[0].pid

                        this.$refs.tree.setChecked(nodes[0], true);

                    } else {

                        if(data.pid !== this.pid) {

                            this.$refs.tree.setChecked(data, false);

                        } else {

                            this.$refs.tree.setChecked(data, true);

                        }

                    }

                }

            })

        },

上一篇 下一篇

猜你喜欢

热点阅读