当前位置:   article > 正文

VUE的el-select下拉框基本用法

el-select

参考:Vue2 el-select下拉框,默认选择第一个值_猫小黑呀的博客-CSDN博客_select下拉框默认选中第一个

el-select下拉框基本写法:

  1. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  2. <el-form-item label="名称">
  3. <el-select v-model="formInline.stationName" @change="onTitleChange">
  4. <el-option v-for="(item,index) in formInline.station" :label="item.station_name" :value="item.station_id"
  5. :key="item.station_id"></el-option>
  6. </el-select>
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button type="primary" icon="el-icon-search">查询</el-button>
  10. </el-form-item>
  11. </el-form>

  1. export default {
  2. name: 'Corporate-Contacts',
  3. data() {
  4. return {
  5. formInline: {
  6. station: [], //station_id的值
  7. station_Name: '', // name
  8. station_Id:'' // 配点站的id
  9. }
  10. }
  11. },
  12. }

分下下分别为三部分:

  1. <el-form :model="formInline" class="demo-form-inline">
  2. </el-form>
  1. <el-select v-model="formInline.stationName" @change="onTitleChange">
  2. </el-select>
  1. <el-option
  2. v-for="(item,index) in formInline.station"
  3. :label="item.station_name"
  4. :value="item.station_id"
  5. :key="item.station_id"
  6. >
  7. </el-option>

第一部分是综合的model,第二部分是你选中的,第三部分下下拉要展示的

复杂的混合模式,嵌套两个下拉框:

  1. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  2. <el-select v-model="formInline.stationName.station_Name" @change="onTitleChange">
  3. <el-option v-for="(item,index) in formInline.stationName.station" :label="item.stationName.station_name" :value="item.stationName.station_id"
  4. :key="item.station_id"></el-option>
  5. </el-select>
  6. <el-select v-model="formInline.TestName.name" @change="inTitleChange">
  7. <el-option v-for="(item,index) in formInline.TestName.station" :label="item.TestName.name" :value="item.TestName.id"
  8. :key="item.station_id"></el-option>
  9. </el-select>
  10. </el-form>
  1. export default {
  2. name: 'Corporate-Contacts',
  3. data() {
  4. return {
  5. formInline: {
  6. stationName:[
  7. station: [], //station_id的值
  8. station_Name: '', // name
  9. station_Id:'' // 配点站的id
  10. ],
  11. TestName:[
  12. station: [], //station_id的值
  13. Name: '', // name
  14. Id:'' // 配点站的id
  15. ],
  16. }
  17. }
  18. },
  19. }

你想获取下拉框的所有内容,对应this.formInline.stationName和this.formInline.TestName

你想获取当前选中了哪个,this.formInline.stationName.station_Name和this.formInline.TestName.Name

默认选中第几项this.formInline.stationName[0].station_Name和this.formInline.TestName[0].Name

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/114778
推荐阅读