国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue3 select循環(huán)多個,選項option不能重復(fù)被選

這篇具有很好參考價值的文章主要介紹了Vue3 select循環(huán)多個,選項option不能重復(fù)被選。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Vue3 select循環(huán)多個,選項option不能重復(fù)被選

環(huán)境:vue3+ts+vite+element plus
實現(xiàn)目標:Vue3 select循環(huán)多個,當其中一個option值被選后,其他select里面不能再重復(fù)選擇該option值。第二種,當其中一個option值被選后,其他select里面就不出現(xiàn)被選option的值

第一種:代碼如下

<template>
    <div>
        <form>
            <table>
                <tr>
                    <td v-for="(option, index) in 4" :key="index">
                        <el-select v-model="selectedOptions[index]" placeholder="請選擇" @change="handleSelectChange(index)" clearable>
                            <el-option v-for="item in optionList" :key="item" :label="item.label" :value="item.value" :disabled="isOptionDisabled(item.value, index)"></el-option>
                        </el-select>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { ElSelect, ElOption } from 'element-plus';

const optionList= [
    { label: '選項1', value: 'option1' },
    { label: '選項2', value: 'option2' },
    { label: '選項3', value: 'option3' },
    { label: '選項4', value: 'option4' },
]
const selectedOptions=ref(<any>['','','',''])
const handleSelectChange=(index: number)=> {
    const selectedValue = selectedOptions[index];
    selectedOptions.value.forEach((value:string, i:number) => {
        if (i !== index && value === selectedValue) {
            selectedOptions[i] = '';
        }
    });
}
const isOptionDisabled=(value: string, currentIndex: number)=> {
    return selectedOptions.value.some((selectedValue, index) => {
        return index !== currentIndex && selectedValue === value;
    });
}
</script>

效果:
Vue3 select循環(huán)多個,選項option不能重復(fù)被選,Vue3,vue3,select option,element-plus
第二種:

<template>
    <tr>
        <td v-for="(option, index) in 3" :key="index">
            <el-select v-model="selectedOptions[index]" placeholder="請選擇" clearable>
                <el-option v-for="item in filteredOptions(index)" 
	                :key="item.value" 
	                :label="item.label" 
	                :value="item.value">
                </el-option>
            </el-select>
        </td>
    </tr>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { ElSelect, ElOption } from 'element-plus';

export default defineComponent({
    components: {
        ElSelect,
        ElOption,
    },
    setup() {
        const optionList = ref([
            { label: '選項1', value: 'option1' },
            { label: '選項2', value: 'option2' },
            { label: '選項3', value: 'option3' },
        ]);
        const selectedOptions = ref([] as string[]);

        function filteredOptions(index: number) {
            const selectedValues = selectedOptions.value.filter((value, i) => i !== index);
            return optionList.value.filter(option => !selectedValues.includes(option.value));
        }

        return {
            optionList,
            selectedOptions,
            filteredOptions,
        };
    },
});
</script>

效果:
Vue3 select循環(huán)多個,選項option不能重復(fù)被選,Vue3,vue3,select option,element-plus
或者用script setup的寫法

<script lang="ts" setup>
import { ref } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
const optionList=[
        { label: '選項1', value: 'option1' },
        { label: '選項2', value: 'option2' },
        { label: '選項3', value: 'option3' },
    ]
const selectedOptions= ref([] as string[])
const filteredOptions=(index: number)=> {
    const selectedValues = selectedOptions.value.filter((value, i) => i !== index);
    return optionList.filter(option => !selectedValues.includes(option.value));
}
</script>

如果沒有使用UI 框架,el-select 和el-option標簽替換為原生HTML標簽即可文章來源地址http://www.zghlxwxcb.cn/news/detail-692446.html

到了這里,關(guān)于Vue3 select循環(huán)多個,選項option不能重復(fù)被選的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 解決element的select組件創(chuàng)建新的選項可多選且opitions數(shù)據(jù)源中有數(shù)據(jù)的情況下,回車不能自動選中創(chuàng)建的問題

    最近開發(fā)項目使用element-plus庫內(nèi)的select組件,其中有提供一個創(chuàng)建新的選項的用法,但是發(fā)現(xiàn)一些小問題,在此記錄 “element-plus”: “^2.3.9”, “vue”: “^3.3.4”, 1、在options數(shù)據(jù)源中無數(shù)據(jù)的時候,在輸入框中輸入要創(chuàng)建的選項,ele會自動幫我們選中第一條,然后回車后會自

    2024年02月11日
    瀏覽(33)
  • 解決Vue中el-select第二次選擇選項時才會顯示上一個選項的響應(yīng)結(jié)果

    解決Vue中el-select第二次選擇選項時才會顯示上一個選項的響應(yīng)結(jié)果

    今天在寫一個選擇器的時候出現(xiàn)一個問題 這個功能需求是:通過選擇器選擇不同的選項,點擊查詢按鈕發(fā)送請求,并將響應(yīng)結(jié)果放到一個div中用v-if控制是否顯示。 看似簡單的一個功能,卻出現(xiàn)一個很搞笑的bug。在我選擇一個選項點擊查詢,本應(yīng)該顯示結(jié)果的div沒有顯示出來

    2024年02月11日
    瀏覽(18)
  • vue element 編輯下拉框el-select不能回顯的問題

    vue element 編輯下拉框el-select不能回顯的問題

    本人的需求是點擊表格里面的編輯按鈕,把數(shù)據(jù)回顯到彈窗內(nèi),其他的都能回顯,但是就下拉框不能正常的回顯 本人后端人員,有不對的地方,勿噴 這是因為點擊編輯,收集到下拉框的value是一個數(shù)字導(dǎo)致的,傳值應(yīng)該是 ‘1’ 而不是 1 解決辦法一:,給彈窗子組件傳參的時

    2024年02月11日
    瀏覽(33)
  • Vue3 實現(xiàn)右擊彈出操作選項

    通過自定義指令來實現(xiàn)右擊彈出操作選項的功能。 創(chuàng)建一個自定義指令 v-context-menu.js: 在Vue應(yīng)用中注冊這個自定義指令: 在組件中使用這個指令:

    2024年03月14日
    瀏覽(29)
  • Vue3---Pinia優(yōu)化重復(fù)請求

    若兩個組件請求的數(shù)據(jù)是相同的,避免請求兩次,可以使用Pinia集中管理數(shù)據(jù),再由父組件請求,子組件使用 1.? 2. 3.

    2024年02月12日
    瀏覽(21)
  • Vue3的手腳架使用和組件父子間通信-插槽(Options API)學(xué)習(xí)筆記

    全局安裝最新vue3 升級Vue CLI: 如果是比較舊的版本,可以通過下面命令來升級 通過腳手架創(chuàng)建項目 父組件 子組件 UserComponent.vue 父組件 **子組件1 JiaComponent.vue ** ** 子組件2 JianComponent.vue ** 父組件 子組件 TitleComponents.vue 父組件 **子組件 NavComponent.vue ** 父組件 子組件 NavCompone

    2024年02月05日
    瀏覽(50)
  • vue3+element-plus實現(xiàn)表格多選功能(可以清除選項或分頁保留選項)

    vue3+element-plus實現(xiàn)表格多選功能(可以清除選項或分頁保留選項)

    如圖所示,在實際開發(fā)中,數(shù)據(jù)量大的表格基本都添加上了分頁功能,每個頁面請求的數(shù)據(jù)回交換更新,第一頁的選中效果在跳轉(zhuǎn)至第二頁后,如果沒有做相關(guān)處理,選中項會被清空,具體解決方法如下 在需要處理的表格標簽中加上 :row-key=\\\"getRowKeys\\\" 以及 @selection-change=“ha

    2024年02月12日
    瀏覽(120)
  • 記錄--vue3 setup 中國省市區(qū)三級聯(lián)動options最簡潔寫法,無需任何庫

    記錄--vue3 setup 中國省市區(qū)三級聯(lián)動options最簡潔寫法,無需任何庫

    在寫頁面的時候,發(fā)現(xiàn)表單里面有一個省市區(qū)的 options 組件要寫,因為表單很多地方都會用到這個地址選擇,我便以為很簡單嘛。 雖然很簡單的一個功能,但是網(wǎng)絡(luò)上能搜索到的教程大多都是需要配合 elementUI 等各種 UI 庫的,但是我的項目并沒有使用這些 UI 庫,何況我只是

    2024年02月05日
    瀏覽(19)
  • [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能

    [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能

    第一章 定制上中下(頂部菜單、底部區(qū)域、中間主區(qū)域顯示)三層結(jié)構(gòu)首頁 第二章 使用Vue3、Element-plus菜單組件構(gòu)建菜單 第三章 使用Vue3、Element-plus走馬燈組件構(gòu)建輪播圖 第四章 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能 [第五章 使用Vue3、Element-plus菜單組件構(gòu)建組圖文章

    2024年02月09日
    瀏覽(35)
  • vue+elementUI el-select 中 沒有加clearable出現(xiàn)一個或者多個×清除圖標問題

    vue+elementUI el-select 中 沒有加clearable出現(xiàn)一個或者多個×清除圖標問題

    1、現(xiàn)象:下方截圖多×清除圖標了 2、在全局common.scss文件中加一個下方的全局樣式noClear 3、在多×清除圖標的組件上層div加noClear樣式 4、 ×清除圖標去除成功

    2024年01月19日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包