vue2 ---过滤器

一、过滤器 —Filters

在这里插入图片描述

二、过滤器基本使用

在这里插入图片描述

三、两种过滤器

  • 私有过滤器:上面写在filters里的过滤器函数即为私有
  • 全局过滤器
    在这里插入图片描述

如果私有过滤器与全局过滤器名字一致,调用私有过滤器

四、品牌案例

 <td>{
    
    {
    
    item.time | dateFormat}}</td>
 ------------------------------------------------
 <script src="https://unpkg.com/[email protected]/dayjs.min.js"></script>
  // 声明初始时间的全局过滤器
  Vue.filter('dateFormat',function (time) {
    
    
    // 1.对time进行格式化,得到HH:mm:ss
    // 2.把格式化的时间显示在页面
    const dtStr =  dayjs(time).format('YYYY-MM-DD HH:mm:ss')
    return dtStr
  })

猜你喜欢

转载自blog.csdn.net/weixin_52905182/article/details/127612903