您好,登錄后才能下訂單哦!
這篇文章主要講解了“vue+element多個相同的select不允許重復選擇問題怎么解決”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“vue+element多個相同的select不允許重復選擇問題怎么解決”吧!
<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: '選項1', label: '黃金糕' }, { id: 2, value: '選項2', label: '雙皮奶', disabled: true }, { id: 3, value: '選項3', label: '蚵仔煎' }, { id: 4, value: '選項4', label: '龍須面' }, { id: 5, value: '選項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 //需要展開內容,顯示與隱藏之間切換 }, toDetail(item) { this.$router.push('/helpDetails/' + item) }, }, mounted() { } } </script>
<style lang="scss" src="@/assets/css/card.scss"></style>
代碼如下:
<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":"選項1" },{ "id":2, "name":"選項2" },{ "id":3, "name":"選項3" }], } }, methods: { onChangeProgram() { this.selectIdsArr = []; for (const item of this.parArr) { if (item.id) { this.selectIdsArr.push(item.id); } } }, }, } </script>
感謝各位的閱讀,以上就是“vue+element多個相同的select不允許重復選擇問題怎么解決”的內容了,經過本文的學習后,相信大家對vue+element多個相同的select不允許重復選擇問題怎么解決這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。