網站首頁 編程語言 正文
有時候因為需求等情況,我們需要拿到select選擇器選擇的整個對象,不光只拿到他的value
當使用element ui 的select選擇器選擇一個選項時,使用@change事件時只能得到一個Id,想要得到Id對應的對象用到filter進行過濾取到才可以。
方式一
<el-select v-model="dataForm.varietyIds" multiple placeholder="請選擇"
@change="changeVarietyIds">
<el-option
v-for="item in options"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
changeVarietyIds(val) {
this.$forceUpdate()
let newList = []
val.map(v => {
const list = this.options.filter(item => {
return item.id === v
})
let obj = list[0]
newList.push(obj)
})
},
方式二
<el-select
value-key="id"
@change="searchSelect"
v-model="addRuleform.diseaseCode"
placeholder="請選擇"
clearable>
<el-option
v-for="item in options"
key="item.id"
:label="item.name"
:value="item">
</el-option>
</el-select>
//change方法
searchSelect(val){
console.log("val",val)
},
這里的重點在于:
1.value-key綁定唯一標識,el-option的key值是不錯的選擇
2.@change方法不帶參數
3.el-option的value綁定的是item對象
結果
?已經拿到了預期的值,后續操作就看需求。
?本文結束。
原文鏈接:https://blog.csdn.net/weixin_43743175/article/details/125165189
相關推薦
- 2023-03-01 shell?wait等待命令的具體使用_linux shell
- 2023-06-19 圖文詳解Go中的channel_Golang
- 2022-06-26 Android界面一鍵變灰開發深色適配模式編程示例_Android
- 2022-09-17 python?pandas處理excel表格數據的常用方法總結_python
- 2022-09-17 ASP.NET?Core中Grpc通信的簡單用法_實用技巧
- 2022-04-07 WPF實現數據綁定_實用技巧
- 2022-06-09 ASP.NET?Core基于現有數據庫創建EF模型_實用技巧
- 2022-10-25 Git中smart?Checkout與force?checkout的區別及說明_相關技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支