Vue2 el-select下拉框,默认选择第一个值

14 篇文章 0 订阅
此博客介绍了如何使用Element UI实现一个企业联系人管理页面,通过el-select组件实现实时选择配电站名,并在change事件中更新station_id。数据从API获取并存储在Vuex状态中,便于状态管理。
摘要由CSDN通过智能技术生成
	 
	 <!-- 下拉框默认选择第一个值 -->
 	<el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="名称">
        <el-select v-model="formInline.stationName" @change="onTitleChange">
          <el-option v-for="(item,index) in formInline.station" :label="item.station_name" :value="item.station_id"
                     :key="item.station_id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search">查询</el-button>
      </el-form-item>
    </el-form>
      
import {
  getStationList
} from '@/api/power-safety/corporate'

export default {
  name: 'Corporate-Contacts',
  data() {
    return {
      formInline: {
        station: [], //station_id的值
        stationName: '', // name
        stationId:'' // 配点站的id
      }
    }
  },
  beforeMount() {
    this.getStationList()
  },
  methods: {
    // 获取配电站列表
    getStationList() {
      getStationList({
        user_id: this.$store.getters.user_id
      }).then(res => {
        this.formInline.station = res.data
        this.formInline.stationName = res.data[0].station_name
        this.formInline.stationId = res.data[0].station_id
        console.log(res)
      })
    },
    //获取动态选中的station_id
    onTitleChange(val){
      this.formInline.stationId = val
      console.log(val)
    }
  }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值