vue2 + antDesign 下拉框限制只能选择2个

vue2 + antDesign v1开发需求下拉框只能选2项,由于v1版不能使用新版属性直接设置,只能手动修改

a-select手动实现选择2个

组件部分

复制代码
<a-form-model
        ref="ruleFormFitup"
        :model="startForm"
        :rules="rulesStartForm"
        :label-col="{ span: 8 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="8">

<a-col :span="12">
            <a-form-model-item
              ref="reviewEngineer"
              label="审核工程师"
              prop="reviewEngineer"
              
            >
              <a-select
                v-model="startForm.reviewEngineer"
                placeholder="请选择"
                allowClear
              show-search
              mode="multiple"
              :filter-option="filterOption"
               @change="handleReviewEngineerChange"
              >
                <a-select-option
                  v-for="item in reviewList"
                  :key="item.oaUser"
                  :value="item.oaUser"
                >
                  {{ item.oaUser }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
</a-row>
</a-form-model>

method中限制选择

复制代码
 handleCheckEngineerChange(value) {
      // 限制最多选择2个
      if (value && value.length > 2) {
        // 只保留前两个选项
        this.startForm.checkEngineer = value.slice(0, 2);
      }
    },
相关推荐
华玥作者1 小时前
[特殊字符] VitePress 对接 Algolia AI 问答(DocSearch + AI Search)完整实战(下)
前端·人工智能·ai
天才奇男子1 小时前
HAProxy高级功能全解析
linux·运维·服务器·微服务·云原生
Mr Xu_1 小时前
告别冗长 switch-case:Vue 项目中基于映射表的优雅路由数据匹配方案
前端·javascript·vue.js
前端摸鱼匠1 小时前
Vue 3 的toRefs保持响应性:讲解toRefs在解构响应式对象时的作用
前端·javascript·vue.js·前端框架·ecmascript
sleeppingfrog1 小时前
zebra通过zpl语言实现中文打印(二)
javascript
lang201509281 小时前
JSR-340 :高性能Web开发新标准
java·前端·servlet
❀͜͡傀儡师2 小时前
centos 7部署dns服务器
linux·服务器·centos·dns
好家伙VCC2 小时前
### WebRTC技术:实时通信的革新与实现####webRTC(Web Real-TimeComm
java·前端·python·webrtc
Dying.Light2 小时前
Linux部署问题
linux·运维·服务器
S19012 小时前
Linux的常用指令
linux·运维·服务器