vue项目 下拉多选树treeselect非空验证

 多选

目录

 多选

 单选:


 

<el-row>
   <el-col :span="24">
        //注意  prop和v-model缺一不可
        //prop="deptIds"单向绑定
       <el-form-item label="所属部门" prop="deptId">
          <treeselect
              v-model="form.deptId"   //双向绑定
              :multiple="true"   //多选
              :options="deptOptions"   //下拉展示的数据源
              @select="ADDselectMember"  //选中触发的函数
              @deselect="DELselectMember" //取消选中触发的函数
              @input="changedetId" 
              placeholder="选择上级部门"/>
        </el-form-item>
   </el-col>
</el-row>



export default {
  name: "Team",
  dicts: ['sys_normal_disable'],
  components: { Treeselect },
  data() {
    return {
  
      deptId:[],
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
       
        deptId: [
          { required: true ,message: "部门名称不能为空", trigger: "input" }
        ],
      }
    };
  },

 methods: {
    ADDselectMember(node,instanceId){
      // console.log("啊啊大大1"+this.form.deptIds)
      console.log("名字"+node.label)
      console.log("id"+node.id)
      this.deptId.push(node.id)
      this.form.deptId = this.deptId
      console.log("新增"+this.deptId)
      // console.log("啊啊大大"+this.form.deptId)

      // console.log("啊啊大大3"+val)
    },
    DELselectMember(node,instanceId){
      for (let i=0; i<this.deptId.length; i++){
        if (this.deptId[i] === node.id){
          this.deptId.splice(i, 1)
          if (this.deptId.length <=1){
            this.form.deptId = this.deptId[0]
          }
          this.form.deptId = this.deptId
          console.log("删除"+this.deptId)

        }
      }
      // this.deptId.pop(node.id)
      // console.log("删除"+this.form.deptIds)
      console.log("删除"+this.deptId)
      // console.log("啊啊大大33"+val)
    },
  }


}

 单选:

 <el-row>
          <el-col :span="24">
            <el-form-item label="所属部门" >
              <treeselect
                    :disabled="viewOrEdit"
                    v-model="form.deptIds"
                    @focus="dis"
                    :multiple="false"
                    :options="deptOptions"
                    @select="ADDselectMember"
                    @input="changedetId"
                    placeholder="请选择部门"/>
            </el-form-item>
          </el-col>
        </el-row>





changedetId(){
      this.$nextTick(()=>{
        this.$refs.form.validateField('deptIds')
      })
    },

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值