后端传数值显示不同的内容,使用filters过滤器优化

后端传数值显示不同的内容,使用filters过滤器优化

1、后端设置传回来的数组对应的内容
在这里插入图片描述
2、使用v-if判断数值的显示

<span v-if='record.building === 1'> 住宅 </span>
<span v-if='record.building === 2'> 商铺</span>
<span v-if='record.building === 3'> 写字楼 </span>
<span v-if='record.building === 4'> 车位</span>
<span v-if='record.building === 5'> 车辆</span>

3、使用filters过滤器优化处理

 filters: {
 	// 第一种学法
    buildingType (value) {
      return [ '住宅', '商铺', '写字楼', '车位' , '车辆' ][value - 1]   
    }
    // 第二种写法
    buildingType  (type) {
      const typeObj = {
        1: '住宅',
        2: '商铺',
        3: '写字楼',
        4: '车位',
        5: '车辆'
      }
      return typeObj[type]
    }
}
// 第一种学法要注意数组的索引值是在0开始的

4、过滤器中template中的使用

<template slot="withhold_subject" slot-scope="withhold_subject, record">
   <div class="fitems-name"> {{ record.building_type | buildingType }} </div>
</template>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值