el的select下拉框对应的列表切换数据

element的select下拉框选择之后,对应的列表上数据对应的切换。
写的是假数据,还没有调接口处理。后续调完接口会回来补上代码
效果:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
因为左边的图标是不变的,所以只处理了右侧的数据
代码


```bash
  <div class="rTop">
        <div style="width: 100%">
          <h3 class="eqName" style="float: left">设备名称</h3>
          <div class="deviceSelect">
          //select的change事件,接的值是目前的选中值,就是当前的id;v-model绑定的值是默认显示第几条,比如data定义的是1,对应的就是设备一。el-option循环的数组就是下拉框所有的选项
            <el-select v-model="value" @change="change($event,item)" id="envirDevice">
              <el-option
                v-for="item in deviceOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <div style="clear: both"></div>
        </div>
        <div>
          <div class="currentData">
            <div class="dataItem">
              <div><img src="./images/hjjcwendu.png" alt="" />温度</div>
              <div class="itemVal wendu">{{ newvalue.temperature }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjcshidu.png" alt="" />湿度</div>
              <div class="itemVal shidu">{{ newvalue.humidity }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjcfengdu.png" alt="" />风速</div>
              <div class="itemVal fengsu">{{ newvalue.wind_speed }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjcfengxiang.png" alt="" />风向</div>
              <div class="itemVal fengxiang">{{ newvalue.wind_direction }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjcPM2.5.png" alt="" />PM2.5</div>
              <div class="itemVal pm25">{{ newvalue.PM2_5 }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjcpm10.png" alt="" />PM10</div>
              <div class="itemVal pm10">{{ newvalue.PM10 }}</div>
            </div>
            <div class="dataItem">
              <div><img src="./images/hjjczaosheng.png" alt="" />噪声</div>
              <div class="itemVal zaosheng">{{ newvalue.noise }}</div>
            </div>
          </div>
        </div>
      </div>
 
 data() {
    return {
       value: '1',//对应的是v-model,默认显示1对应的label

       newvalue:{},//准备空对象用来接change事件里发生改变时新的对象
       deviceOptions: [//option的数组
        { label: "设备一", value: "1" },
        { label: "设备二", value: "2" },
        { label: "设备三", value: "3" },
      ], 
      
       currentData: [//假数据,三个对象分别对应三个选项
         {
           temperature:'32.2',
           humidity:'70.2',
           wind_speed:'0.5',
           wind_direction:'127',
           PM2_5:'41',
           PM10:'14',
           noise:'98.6',
         }, 
{
           temperature:'3.2',
           humidity:'7.2',
           wind_speed:'0.5',
           wind_direction:'127',
           PM2_5:'41',
           PM10:'14',
           noise:'98.6',
         },
         {
           temperature:'4.2',
           humidity:'70.2',
           wind_speed:'0.5',
           wind_direction:'127',
           PM2_5:'41',
           PM10:'14',
           noise:'98.6',
         },
       ],
        
    };
  },
methods: {
      change(item) {//change事件,空对象用来接对应的选项的数据,this.currentData[item]代表数组里的每一项,[item-1]是因为item是1、2、3,而数组的下标是0、1、2。
        console.log(item,'111',);
     this.newvalue =this.currentData[item-1];

    },
    }

样式的代码仅供参考

.hjjcblock .rTop {

  width: 100%;
  height: 510px;

}
.hjjcblock .deviceSelect {
  float: right;
  padding: 20px 30px;
  position: relative;
  color: #616263;
  overflow: hidden;
  display: block;
}
.hjjcblock .deviceSelect:after {
  /*content:"▼";*/
  padding: 12px 8px;
  position: absolute;
  right: 45px;
  top: 12px;
  z-index: 1;
  text-align: center;
  width: 10%;
  height: 100%;
  pointer-events: none;
  box-sizing: border-box;
  color: #fff;
}

.currentData {
  margin: auto 30px;
  /*width: 100%;*/
}
.eqName{
  color: #fff;
  font-size: 16px;
  margin-left: 20px;
  margin-top: 30px;
}
.currentData .dataItem {
  /*width: 100%;*/
  display: flex;
  justify-content: space-between;
  font-size: 18px;
   background: url("./images/shishishuju_bg.png") no-repeat;
  background-size: 100% 100%;
color:#00FCFF;
  line-height: 40px;
  margin-bottom: 18px;
  align-items: center;
  padding: 0 20px;
}
.currentData .dataItem div img {
  margin-right: 8px;
  margin-bottom: -7px;
  margin-top: 5px;
}
.currentData .dataItem .itemVal {
  color: #fff;
}
.el-select .el-input__inner {
  height: 30px !important;
  line-height: 30px !important;
  background: #03739b;
  border: none;
  color: #fff;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-color: transparent;
  width: 125px;
}

.el-select .el-tag {
  background-color: transparent !important;
  color: #fff !important;
  border-color: #fff !important;
  margin: 1px 0 1px 6px !important;
}
.el-select .el-input .el-select__caret {
  color: #fff;
}
.el-icon-arrow-up:before {
  content: "▲"; /*▲*/
}
.el-input__icon {
  line-height: 30px !important;
}
.select {
  background: #03739b;
  border: none;
  color: #fff;
  width: 125px;
  height: 25px;
  border-radius: 4px;
  padding: 2px 12px;
  font-size: 15px;
  border: 0;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值