[element-ui] el-tree实现全选/反选、默认全选

<el-form-item label="字段选择" :label-width="formLabelWidth">
        <div class="propLists">
          <div class="propListHeader">
            <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="checkAllChange">全部选择</el-checkbox>
          </div>
          <div class="propListBody">
            <el-tree ref="channelTree" :data="props" :props="defaultProps" node-key="id" show-checkbox @check-change="handleCheckChange"></el-tree>
          </div>
 
        </div>
</el-form-item>
watch:{
  visibleExcel(newVal) {  //在弹框打开时默认执行全选方法,
      if (newVal) {
        this.checkAllChange()
      }
    },
} 
 
methods: {   
// 全选或反选
    checkAllChange() {
      if (this.checkAll) { // 全选
        this.$nextTick(() => {    //这个如果要默认全选就必须加,否则会报错“setCheckedNodes”未定义
          this.$refs.channelTree.setCheckedNodes(this.props)
        })
        // this.
      } else { // 取消选中
        this.$nextTick(() => {
          this.$refs.channelTree.setCheckedKeys([])
        })
      }
    },
}


el-tree实现全选/反选、默认全选

你可能感兴趣的:(element-ui,javascript)