vue+element 多個(gè)相同的select不允許重復(fù)選擇問題
更新時(shí)間:2022年07月07日 14:52:14 作者:qq_25537391
這篇文章主要介紹了vue+element 多個(gè)相同的select不允許重復(fù)選擇問題,具有很好的參考價(jià)值,希望對大家有所幫助。
element多個(gè)相同的select不允許重復(fù)選擇
<template> ? <div class="com_searchAndpageBoxPadding"> ? ? <div> ? ? ? <el-select v-model="value1" placeholder="請選擇"> ? ? ? ? <el-option v-for="item in haha" :key="item.id" :label="item.label" :value="item.id" :disabled="disabledChoose(item)"> ? ? ? ? </el-option> ? ? ? </el-select> ? ? ? <el-select v-model="value2" placeholder="請選擇"> ? ? ? ? <el-option v-for="item in haha" :key="item.id" :label="item.label" :value="item.id" :disabled="disabledChoose(item)"> ? ? ? ? </el-option> ? ? ? </el-select> ? ? ? <el-select v-model="value3" placeholder="請選擇"> ? ? ? ? <el-option v-for="item in haha" :key="item.id" :label="item.label" :value="item.id" :disabled="disabledChoose(item)"> ? ? ? ? </el-option> ? ? ? </el-select> ? ? </div> ? </div> </template>
<script>
export default {
? data() {
? ? return {
? ? ? value1: '',
? ? ? value2: '',
? ? ? value3: '',
? ? ? haha: [{
? ? ? ? id: 1,
? ? ? ? value: '選項(xiàng)1',
? ? ? ? label: '黃金糕'
? ? ? }, {
? ? ? ? id: 2,
? ? ? ? value: '選項(xiàng)2',
? ? ? ? label: '雙皮奶',
? ? ? ? disabled: true
? ? ? }, {
? ? ? ? id: 3,
? ? ? ? value: '選項(xiàng)3',
? ? ? ? label: '蚵仔煎'
? ? ? }, {
? ? ? ? id: 4,
? ? ? ? value: '選項(xiàng)4',
? ? ? ? label: '龍須面'
? ? ? }, {
? ? ? ? id: 5,
? ? ? ? value: '選項(xiàng)5',
? ? ? ? label: '北京烤鴨'
? ? ? }],
? ? }
? },
? computed: {
? ? disabledChoose(item) {
? ? ? return function (item) {
? ? ? ? let findItemIndex = [this.value1, this.value2, this.value3].findIndex(item2 => item2 == item.id);
? ? ? ? console.log('findItemIndex', findItemIndex)
? ? ? ? let newArr = [this.value1, this.value2, this.value3].splice(findItemIndex, 1);
? ? ? ? console.log('newArr', newArr)
? ? ? ? return newArr.includes(item.id);
? ? ? }
? ? }
? },
? methods: {
? ? showToggle(item) {
? ? ? item.isSubShow = !item.isSubShow //需要展開內(nèi)容,顯示與隱藏之間切換
? ? },
? ? toDetail(item) {
? ? ? this.$router.push('/helpDetails/' + item)
? ? },
? },
? mounted() {
? }
}
</script><style lang="scss" src="@/assets/css/card.scss"></style>
動(dòng)態(tài)循環(huán)出的多個(gè)select 不能重復(fù)選擇相同的數(shù)據(jù)
先看效果圖

代碼如下:
<template>
? <div class="program" v-for="(parItem,index) in parArr" :key="parItem.guid">
? ? <Select v-model="parItem.id" ?@on-change="onChangeProgram">
? ? ? <Option v-for="(subItem,idx) in programList" :key="subItem.id" :data-index='idx'
? ? ? ? v-show="parItem.id == subItem.id || !selectIdsArr.includes(subItem.id)"
? ? ? ? :value="subItem.id> {{subItem.name}}</Option>
? ? </Select>
? </div>
</template><script>
export default {
? data() {
? ? return {
? ? ? parArr:[{guid:'ddddd',id:null,},{guid:'eeeee',id:null,},{guid:'ffff',id:null,}],
? ? ? selectIdsArr:[],
? ? ? programList:[{
? ? ? ? "id":1,
? ? ? ? "name":"選項(xiàng)1"
? ? ? },{
? ? ? ? "id":2,
? ? ? ? "name":"選項(xiàng)2"
? ? ? },{
? ? ? ? "id":3,
? ? ? ? "name":"選項(xiàng)3"
? ? ? }],
? ? }
? },
? methods: {
? ? onChangeProgram() {
? ? ? this.selectIdsArr = [];
? ? ? for (const item of this.parArr) {
? ? ? ? if (item.id) {
? ? ? ? ? this.selectIdsArr.push(item.id);
? ? ? ? }
? ? ? }
? ? },
? },
}
</script>以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3全局屬性app.config.globalProperties的實(shí)現(xiàn)
Vue3中的app.config.globalProperties是一個(gè)強(qiáng)大的全局配置功能,允許我們在應(yīng)用級別設(shè)置和訪問屬性,本文主要介紹了Vue3全局屬性app.config.globalProperties的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
如何測量vue應(yīng)用運(yùn)行時(shí)的性能
這篇文章主要介紹了如何測量vue應(yīng)用運(yùn)行時(shí)的性能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,,需要的朋友可以參考下2019-06-06
Vue?Input輸入框自動(dòng)獲得焦點(diǎn)的有效方法
我們有時(shí)候會(huì)遇到要輸入框自動(dòng)獲取焦點(diǎn)的情況,下面這篇文章主要給大家介紹了關(guān)于Vue?Input輸入框自動(dòng)獲得焦點(diǎn)的簡單方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
詳解為element-ui的Select和Cascader添加彈層底部操作按鈕
這篇文章主要介紹了詳解為element-ui的Select和Cascader添加彈層底部操作按鈕,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
el-table-column 內(nèi)容不自動(dòng)換行的解決方法
本文主要介紹了el-table-column 內(nèi)容不自動(dòng)換行的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
基于Electron+Vite快速構(gòu)建Vue3桌面應(yīng)用
這篇文章主要介紹了如何基于Electron和Vite快速構(gòu)建Vue3桌面應(yīng)用,本文主要技術(shù)棧就是Vue3、vite、Electron,文中有詳細(xì)的代碼示例,需要的朋友可以參考下2023-07-07
Mock.js在Vue項(xiàng)目中的使用小結(jié)
這篇文章主要介紹了Mock.js在Vue項(xiàng)目中的使用,在vue.config.js中配置devServer,在before屬性中引入接口路由函數(shù),詳細(xì)步驟跟隨小編通過本文學(xué)習(xí)吧2022-07-07

