computed,switch,根据文字内容改变颜色/watch/props对象

  props:{
        currentPersonIsland:{
            typeof:'Object',
            default () {
                return {}
                }
        }
    },

watch: {
    //   这是深度监听,适合监听数组对象
      currentPersonIsland: {
          handler(val) {
              this.dealList(val)
          },
          deep: true
      },
    //   如果是个字符串,数字是值类型,普通监听就够了
    currentPersonIsland(newVal, oldVal) { // 可以监听 data里面的内容,也可以监听props 不能自己捏造一个
        // newVal 是变化后的新值 oldVal是旧值 这是自带的两个形参
        // 他的值变化后就会触发这里的方法
    }
  },
<div class="register">
              <span>订单状态</span>
              <p
                class="withdrawal_num"
                :class="colorStyle"
              >
                {{ filterStatus(item.earn_profit_type) }}
              </p>
            </div>

//js部分:
   computed:{
        colorStyle(){
            let name = ''
            switch(item.earn_profit_type){
                case:'10':
                name="green"
                break;
                case:'11||12':
                name="yellow"
                break;
                case:'':
                name="red"
                break;
             }
            return name
            }
    },            
filterStatus(val) {
      if (val == "10") {
        return "已购买";
      } else if (val == "11" || val == "12") {
        return "退卡中";
      } else {
        return "未购买";
      }
    }
//css部分
.green {
  color: #39b54a;
}
.yellow {
  color: #f29124;
}
.red {
  color: #e6432d;
}

computed,switch:根据后台接口返回的数据(this.weatherList[3].value)优良轻度污染重度污染等。显示不同的图片不同的文字。

 <p  >{{weatherGrade}}</p>


computed:{
    weatherGrade(){
      switch(this.weatherList[3].value){
          case '优' :
            this.picturePng=grade01;
            break;
          case '良' :
            this.picturePng=grade02;         
            break;
          case '轻度污染' :
            this.picturePng=grade03;
            break;
          case '中度污染' :
            this.picturePng=grade04;
            break;
          case '重度污染' :
            this.picturePng=grade05;
            break;
          case '严重' :
            this.picturePng=grade06;
            break;
            }
          return this.picturePng,this.weathList[3].value
}
  },

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值