a-select中placeholder设置无效的解决办法(两种情况)

1 篇文章 0 订阅

需求:1. a-select绑定基础类型数据
           2. a-select使用了labelInValue,绑定的数据类型为对象

方式一:只取option的value值

<a-select placeholder="请选择功能类型"
          v-model="submitObj.operation"
          @change="typeChange">
  <a-select-option v-for="(item, index) in operTypeArr"
                   :key="index"
                   :value="item.dict_entry">{{item.dict_value}}</a-select-option>
</a-select>

// 重置表单的时候这里的operation也要重置成undefined
submitObj: {
  operation: undefined,
  name: '',
  note_explain: ''
}

方式二:使用了labelInValue

<!-- 此处不用v-model,如果还是想用可通过计算属性的get和set实现下 -->
<a-select placeholder="请选择功能类型"
          labelInValue
          :value="submitObj.operation.label ? submitObj.operation : undefined"
          @change="typeChange">
  <a-select-option v-for="(item, index) in operTypeArr"
                   :key="index"
                   :value="item.dict_entry">{{item.dict_value}}</a-select-option>
</a-select>

// 重置表单的时候这里operation的label也要清空
submitObj: {
  operation: {
    label: '',
    key: ''
  },
  name: '',
  note_explain: ''
}

typeChange (item) {
  // 此处的item格式如下
  // {
  //    label: **,
  //    key: **
  // }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值