vue 过滤器 filters 的使用

vue 过滤器 filters 的使用

代码:

<template>
  <div>
    <table border="1" style="width: 300px">
      <tr>
        <th>id</th>
        <th>商品名称</th>
        <th>商品状态</th>
      </tr>
      <tr v-for="(item, index) of list" :key="index">
        <td>{{item.id}}</td>
        <td>{{item.name}}</td>
        <!--filters过滤器使用-->
        <td :class="item.status | orderStatusClass">{{item.status | orderStatus}}</td> 
      </tr>
    </table>
  </div>
</template>

<script>
const orderStatus = (val)=>{
  switch (val){
    case 0:
      return '待支付';
    case 1:
      return '代发货';
    case 2:
      return '待收货';
    case 3:
      return '待评论';
  }
}
const orderStatusClass = (val)=>{
  switch (val){
    case 0:
      return 'not-pay';
    case 1:
      return 'not-send';
    case 2:
      return 'not-receipt';
    case 3:
      return 'not-comment';
  }
}
export default {
  name: "index",
  filters: { // filters过滤器
    orderStatus,
    orderStatusClass,
  },
  data() {
    return {
      list:[
        {id:1,name:'商品1',status: 0},
        {id:2,name:'商品2',status: 1},
        {id:3,name:'商品3',status: 2},
        {id:4,name:'商品4',status: 3},
        {id:5,name:'商品5',status: 0},
        {id:6,name:'商品6',status: 1},
      ]
    };
  },
};
</script>

<style scoped>
  .not-pay{
    color: red;
  }
  .not-send{
    color: olive;
  }
  .not-receipt{
    color: blue;
  }
  .not-comment{
    color: black;
  }
</style>

效果显示:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值