el-select实现动态从后台获取,遍历写出选项

2022-09-15 14:18:51

首先,在data中声明一个值

 data(){return{
      dishesInfoList:[],}}

其次,在查询遍历列表信息的接口中获取数据

 listDishesInfo(this.queryParams).then(response=>{
        this.dishesInfoList= response.data;});

之后,在el-form中写上 : data;在el-select中写上v-model(写不写都行);
在el-option里面写上

	v-for="item in dishesInfoList"
		:key="item.id"
		:value="item.shopId"
		:label="item.shopId"

具体代码如下:

<el-form ref="form"  :data="dishesInfoList"><el-select
   v-model="dishesInfoList.shopId"//在这里写上
   placeholder="选择店铺"
   clearable
   @keyup.enter.native="handleQuery"><el-option v-for="item in dishesInfoList"
              :key="item.id"
              :value="item.shopId"
              :label="item.shopId"></el-option></el-select>
  • 作者:qq_45489665
  • 原文链接:https://blog.csdn.net/qq_45489665/article/details/115600858
    更新时间:2022-09-15 14:18:51