vue之级联选择器选中拿到当前全部数据(elementU)

业务需求:应后台要求接收的数据是多个,在级联选择器中只能拿到指定的值,固解决如何拿到多个值传入后台。

代码结构:

<el-form-item label="分类">
  <el-cascader
     v-model="formInline.classification"
     :options="classificationOpt"
     :props="{
        label: 'cloumName',
        value: 'id',
        checkStrictly: true,
     }"
      clearable
     ref="cascaderAddr"
      @change="classChange" >
      </el-cascader>
 </el-form-item>
data () {
    return {
	    classification:[],//接收的数组
	    formInline: {
	        classification: {}, // 分类显示
	        classifyValue: '' // 分类接收数据
	     }
	}
  },
  // 获取分类选中数据
    classChange () {
      if (
        this.$refs.cascaderAddr.getCheckedNodes() && this.$refs.cascaderAddr.getCheckedNodes()[0]
      ) {
        const nodeContent = this.$refs.cascaderAddr.getCheckedNodes()[0].data
        console.log(nodeContent )//这个位置可以打印一下
        this.formInline.classifyValue = nodeContent
      } else {
        this.formInline.classifyValue = null
      }
    },

此时的你就可以拿到你选中的全部,然后在接口传值的时候将你于后台规定的字段填写正确即可,当添加了清除 clearable 时会在控制台报错,所以在change事件里进行判断。

//传入接口数据结构
 chooseAttrDTO: {
          cloumName: this.formInline.classifyValue.cloumName ? undefined : '',
          cloumSign: this.formInline.classifyValue.cloumSign ? undefined : '',
          id: this.formInline.classifyValue.id ? undefined : ''
        }
总结:因为在element 组件级联选择器只能指定固定的值,如果用之前的写法只能拿到一个值,所以添加一个ref,使用getCheckedNodes()的方法来获取全部的数据。
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值