vue+element多个相同的select不允许重复选择问题怎么解决

发布时间:2022-07-08 09:42:44 作者:iii
来源:亿速云 阅读:1091

这篇文章主要讲解了“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不允许重复选择问题怎么解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. windows 解决SID相同的问题
  2. select选择多个值的方式

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue element select

上一篇:微信小程序怎么实现简单弹框效果

下一篇:package.json管理依赖包版本实例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》