vue+element 多個(gè)相同的select不允許重復(fù)選擇問題
element多個(gè)相同的select不允許重復(fù)選擇
<template> ? <div class="com_searchAndpageBoxPadding"> ? ? <div> ? ? ? <el-select v-model="value1" placeholder="請(qǐng)選擇"> ? ? ? ? <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="請(qǐng)選擇"> ? ? ? ? <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="請(qǐng)選擇"> ? ? ? ? <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項(xiàng)目啟動(dòng)自動(dòng)打開瀏覽器以及server配置過程
這篇文章主要介紹了vue3項(xiàng)目啟動(dòng)自動(dòng)打開瀏覽器以及server配置過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03vue3中require報(bào)錯(cuò)require is not defined問題及解決
這篇文章主要介紹了vue3中require報(bào)錯(cuò)require is not defined問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06詳解探索 vuex 2.0 以及使用 vuejs 2.0 + vuex 2.0 構(gòu)建記事本應(yīng)用
本篇文章主要介紹了詳解探索 vuex 2.0 以及使用 vuejs 2.0 + vuex 2.0 構(gòu)建記事本應(yīng)用 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06vue使用GraphVis開發(fā)無限拓展的關(guān)系圖譜的實(shí)現(xiàn)
本文主要介紹了vue使用GraphVis開發(fā)無限拓展的關(guān)系圖譜,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08從Echarts報(bào)錯(cuò)中學(xué)習(xí)Vue3?ref和shallowRef區(qū)別及其組件二次封裝demo
這篇文章主要介紹了從Echarts報(bào)錯(cuò)中學(xué)習(xí)Vue3?ref和shallowRef區(qū)別及其組件二次封裝demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11一文搞懂Vue3中toRef和toRefs函數(shù)的使用
這篇文章主要為大家介紹了Vue3中toRef和toRefs函數(shù)的使用方法,文中通過示例為大家進(jìn)行了詳細(xì)的講解,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-07-07