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

 


        
全部选择

 

 

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([])
        })
      }
    },
}

 

你可能感兴趣的:(elementui,vue项目开发,vue学习笔记,vue.js,前端)