Vue中注册全局过滤器

main.js 中添加

Vue.filter('过滤器的名字',function(需要处理的原始数据){
      const dt = new Data(需要处理的原始数据)

     const y = dt.getFullYear()
     const m = (dt.getMonth() + 1 + '').padStar(2,'0')
      ···
      ···
     return `${y}-${m}`
})

.padStar是用来填充不足的位数
.padStar(不足2位,用'0'来填充)


如何使用过滤器

<template slot-scope="scope">
      {{scope.row.time | 过滤器的名字}}
</template>
posted @ 2020-10-30 13:37  张新钢  阅读(144)  评论(0)    收藏  举报