vue element-ui Select 选择器自定义模版

1:应用场景
(0-1)当后端给我们下拉选择时,需要我们展示更多的内容以便使用者更清晰的选择哪一个

在这里插入图片描述

<template slot-scope="scope">
            <el-select v-model="scope.row.room_number" placeholder="全部房间" size="mini"  @change="onGuestRoom" @focus="getGuestRoom" >
              <el-option
                v-for="item in guest_room_list"
                :key="item.room_number"
                :label="item.room_number"
                :value="item.room_number">
                <span style="float: left">{{ item.room_number }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">可排人数{{ item.count }}</span>
              </el-option>
            </el-select>
          </template>
            /*这里可以实现下拉选择展示内容
             <span style="float: left">{{ item.room_number }}</span>
             <span style="float: right; color: #8492a6; font-size: 13px">可排人数{{ item.count }}</span>*/

2:拓展场景
(0-1)在后端给我们的数据里有一项可排人数我们需要用到用以判断,但是我们使用change 事件时我们只能拿到 :value=“item.room_number” 这个值,那这个时候我们怎么办呢?

//我们要获取guest_room_list
//其次我们在data里声明一个对象guest_room_dic
 that.$axios({
          url:that.url+"/v1/bill/get_reserve_base_house_list/"+that.id,
          method:"post"
        })
          .then(res=>{
            if(res.data.message==="success"){
              that.guest_room_list=res.data.data;
              //这里使用guest_room_dic对象的key = 我们change事件取到的值,方便使用key 取value
              for(let i of that.guest_room_list){
                this.guest_room_dict[i['room_number']] = i
              }
            }else {
              that.hintInfo("warning","获取列表失败"+res.data.message)
            }
          })
          .catch(err=>{
            that.hintInfo("warning","获取列表失败"+err)
          })

在这里插入图片描述
(0-2)在change事件地方使用就行了

 onGuestRoom(value){
        let that =this;
         //that.guest_room_dict[value];//这个就是把选择的数据当作对象的key 取得value 
        let count = that.guest_room_dict[value].count
     
      },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值