Vue3+ Element-plus,使用el-select 循环多个下拉选择框时,选项option不能重复被选;选择后的option,在别的下拉中显示禁用状态

本文介绍了如何在Vue3和Element-plus框架下,使用el-select组件创建多个下拉选择框时,确保已选择的option不重复并显示为禁用状态。通过示例代码展示了实现这一功能的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍

Vue3.2中使用Element-plus框架里的 el-select,实现循环多个下拉选项列表;下拉列表数据为同一个;但是当前已经选中的option,在别的下拉中显示为禁用状态;如下图所示;

在这里插入图片描述

代码:

<div v-for="(option,index) in titleList" :key="index">
   <div class="login-item login-register-code flex flex-row align-items-center">
     <div class="title">{
  {option}}:</div>
     <el-form-item style="width: 80%; margin-bottom:0 ">
       <el-select v-model="selectedOptions[index]" placeholder="请选择问题"
         @change="handleSelectChange(index)" clearable
       >
         <el-option :label=</
使用Vue 3结合element-plus库来创建一个简单的汇率转换器,你可以按照以下步骤进行: 1. 初始化Vue项目: 首先,确保你已经安装了Node.js和npm。然后,使用Vue CLI来创建一个新的Vue 3项目: ```bash npm install -g @vue/cli vue create currency-converter ``` 选择Vue 3作为项目版本。 2. 安装element-plus: 在你的Vue项目中安装element-plus,一个基于Vue 3的组件库: ```bash cd currency-converter npm install element-plus --save ``` 3. 在main.js中引入element-plus: ```javascript import { createApp } from &#39;vue&#39;; import App from &#39;./App.vue&#39;; import ElementPlus from &#39;element-plus&#39;; import &#39;element-plus/dist/index.css&#39;; const app = createApp(App); app.use(ElementPlus); app.mount(&#39;#app&#39;); ``` 4. 创建汇率转换器组件: 在你的`src/components`目录下创建一个名为`CurrencyConverter.vue`的新文件,并添加以下代码: ```vue <template> <el-form ref="form" :model="form" label-width="100px"> <el-form-item label="选择货币"> <el-select v-model="form.currency" placeholder="请选择货币"> <el-option v-for="item in currencies" :key="item.value" :label="item.label" :value="item.value"> <template #default="data"> <img :src="data.icon" alt="icon" style="width: 20px; height: 20px; margin-right: 10px;vertical-align: middle" /> {{ data.label }} </template> </el-option> </el-select> </el-form-item> </el-form> </template> <script setup> import { reactive, ref } from &#39;vue&#39;; const currencies = [ { value: &#39;USD&#39;, label: &#39;美元&#39;, icon: &#39;path_to_usd_icon&#39; }, { value: &#39;EUR&#39;, label: &#39;欧元&#39;, icon: &#39;path_to_eur_icon&#39; }, // 更多货币... ]; const form = reactive({ currency: &#39;&#39;, }); const $ = ref(null); </script> <style scoped> /* 你的样式 */ </style> ``` 请将`path_to_usd_icon`和`path_to_eur_icon`替换为实际的图片路径。 5. 在App.vue使用`CurrencyConverter`组件: ```vue <template> <div id="app"> <currency-converter /> </div> </template> <script> import CurrencyConverter from &#39;./components/CurrencyConverter.vue&#39;; export default { name: &#39;App&#39;, components: { CurrencyConverter, }, }; </script> <style> /* 全局样式 */ </style> ``` 确保你已经在`src/components`目录下创建了`CurrencyConverter.vue`文件,并且路径是正确的。 以上步骤提供了一个基础的汇率转换器框架。你需要添加逻辑来处理汇率的获取和转换,这通常涉及到调用外部API来获取实汇率数据,然后使用这些数据来计算转换后的金额。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值