ELementUI select多选下拉框获取选中项的全部属性

<template>
  <el-select v-model="value1" multiple placeholder="请选择">//multiple  多选,去掉就是单选
    <el-option
      v-for="item in options"  //循环添加下拉选项,options数据源遍历对象,item数据源中的元素
      :key="item.value"       //元素的主键
      :label="item.label"     //选中显示到选项框中的属性
      :value="item.value">    //绑定到 value1中的属性,用于提交的数据
    </el-option>
  </el-select>
</template>

原版的value1只会增加选项的value属性的值,但是有时需要提交的数据不止一个属性,所以需要提交多个属性或全部属性

解决方案:在<el-select>标签上添加  value-key="id" change="changeValue"     修改<el-option>标签上的:value="item"
 

<template>
     <el-select v-model="entity.specIds" multiple placeholder="请选择" value-key="id" change="changeValue"
 style="width:100%;">
          <el-option
               v-for="item in specList"
               :key="item.id"
               :label="item.text"
               :value="item">
          </el-option>
      </el-select>
</template>

style="width:100%;"   修改宽度

发布了29 篇原创文章 · 获赞 24 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/lijiabinbbg/article/details/105140336