这篇文章主要讲解了“vue+element多个相同的select不允许重复选择问题怎么解决”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“vue+element多个相同的select不允许重复选择问题怎么解决”吧!
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>
动态循环出的多个select 不能重复选择相同的数据
代码如下:
<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不允许重复选择问题怎么解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!