首页IT科技el-select 获取label值(el-select如何获取下拉框选中label和value的值)

el-select 获取label值(el-select如何获取下拉框选中label和value的值)

时间2025-05-05 16:32:10分类IT科技浏览4855
导读:【示例1】 <...

【示例1】

<templete slot-scope="scope"> <el-form-item :prop="list. + scope.$index + .goodModularId"> <!-- change事件中            ,会获取到当前选中的值(因为默认会将event参数传递过去; 如果想要传递多个值                    ,change($event, "传递的其他值")       ,将“选中的当前元素             ” 和 “传递的其他值                   ” 一起传递过去 --> <el-select v-model="ruleForm.goodModularId" @change="getModularValue($event, scope.$index)" @clear="delModularValue(scope.$index)"> <el-option v-for="(item,index) in modularData" :key="index" :value="item.id" :label="item.name"></el-option> </el-select> </el-form-item> </templete> <script> data() { return { ruleForm: { list: [{ goodModularId: , goodModular: }] } } } methods: { // 获取value值给goodModular getModularValue(val,index) { let obj = this.modularData.find(item => item.id === val) // 判断的时候可以直接写obj而不需要以判断对象是否为空的方式是因为:如果找不到            ,find方法返回的是undefined而不是空对象 if(obj) { this.ruleForm.list[index].goodModular = obj.name } else { this.ruleForm.list[index].goodModular = } } // 清空选项事件 delModularValue(index) { this.ruleForm.list[index].goodModular = } } </script>

【示例2】

<templete slot-scope="scope"> <el-form-item :prop="list. + scope.$index + .goodModularId"> <el-select v-model="ruleForm.goodModularId" @clear="delModularValue(scope.$index)"> <el-option v-for="(item,index) in modularData" :key="index" :value="item.id" :label="item.name" @click.native="getModularValue(item.id, scope.$index)"></el-option> </el-select> </el-form-item> </templete> <script> data() { return { ruleForm: { list: [{ goodModularId: , goodModular: }] } } } methods: { getModularValue(val,index) { let obj = this.modularData.find(item => item.id === val) if(obj) { this.ruleForm.list[index].goodModular = obj.name } else { this.ruleForm.list[index].goodModular = } }, delModularValue(index) { this.ruleForm.list[index].goodModular = } } </script>

【示例3】

<el-form-item label="类别" prop="categoryId"> <el-select v-model="ruleForm.categoryId" @clear="clearCategory"> <el-option v-for="(item,index) in categoryOptions" :key="item.id" :value="item.id" :label="item.name" @click.native="getValue(item.name, categoryName)"></el-option> </el-select> </el-form-item>
getValue(val, type) { this.ruleForm[type] = val } clearCategory() { this.ruleForm.categoryName = }

总结

到此这篇关于el-select如何获取下拉框选中label和value值的文章就介绍到这了,更多相关el-select获取下拉框选值内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!

声明:本站所有文章                   ,如无特殊说明或标注       ,均为本站原创发布             。任何个人或组织      ,在未征得本站同意时                   ,禁止复制             、盗用                   、采集       、发布本站内容到任何网站      、书籍等各类媒体平台                   。如若本站内容侵犯了原著者的合法权益             ,可联系我们进行处理       。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
微前端解决什么问题(微前端架构-qiankun在vue3的应用)