«

vue中的各种过滤器

yang 发布于 阅读:406 Vue2阶段


1.全局不足十补零过滤器(全局 main.js)

Vue.filter("fillZero", (num) => {
  return num < 10 ? "0" + num : num;
});

2.价格保留两位小数

当前页面

// 过滤器
  filters: {
    // 保留两位小数
    filtersPrice(num) {
      return Number(num).toFixed(2);
    },
    // 三目表达式
    // filtersOne(num) {
    //   return num < 10 ? "0" + num : num;
    // },
  },

挂载全局 main.js

Vue.filter(
  // 保留两位小数
  "filtersPrice",
  (num) => {
    return Number(num).toFixed(2);
  }
  // 三目表达式
  // filtersOne(num) {
  //   return num < 10 ? "0" + num : num;
  // },
),

vue中的各种过滤器

版权所有:微4e
文章标题:vue中的各种过滤器
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论