美文网首页
vue全局过滤器 格式化时间

vue全局过滤器 格式化时间

作者: 用心为你 | 来源:发表于2020-04-17 10:38 被阅读0次

1、在main.js中定义

// 格式化时间
Vue.filter('formatDate', function (value) {
  let date = new Date(value);
  let y = date.getFullYear();
  let MM = date.getMonth() + 1 + "";
  MM = parseInt(MM) < 10 ? "0" + MM : MM;
  let d = date.getDate() + "";
  d = parseInt(d) < 10 ? "0" + d : d;
  let h = date.getHours() + "";
  h = parseInt(h) < 10 ? "0" + h : h;
  let m = date.getMinutes() + "";
  m = parseInt(m) < 10 ? "0" + m : m;
  let s = date.getSeconds() + "";
  s = parseInt(s) < 10 ? "0" + s : s;
  return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
})

2、在组件中使用

<el-table-column property="lastUpdateTime" label="上次修改时间" width="180">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.lastUpdateTime  | formatDate }}</span>
          </template>
  </el-table-column>

结果:
2020-01-02 00:00:00

相关文章

  • vue filter 过滤器使用

    格式化时间 自定义全局过滤器 vue 自定义过滤器分为"全局过滤器"和"局部过滤器"两种。 一、 全局过滤器 全局...

  • 13、vue 中格式化时间

    过滤器格式化时间 date.js 格式化方法使用 vue中过滤器使用 v-model中格式化时间(过滤器就失效了)...

  • Vue的过滤器

    过滤器 filter 作用:文本数据格式化 两种过滤器:1 全局过滤器 2 局部过滤器 全局过滤器 说明:通过全局...

  • vue中过滤器filters

    vue中允许你自定义过滤器,用于一些文本的格式化。 组件中定义过滤器 全局定义过滤器 过滤器传参 传一个参数 传2...

  • 过滤器

    品牌实例 全局过滤器 Vue中允许自定义过滤器,可被用作一些常见的文本格式化;过滤器可用在两个地方:mustach...

  • vue全局过滤器 格式化时间

    1、在main.js中定义 2、在组件中使用 结果:2020-01-02 00:00:00

  • VUE-定义全局过滤器(时间)

    今天我们来学习一下,如何在VUE项目中格式化时间的全局过滤器。 在main.js文件中定义如下内容 在文件中使用 ...

  • vue自定义过滤器

    Vue的自定义过滤器有两种:全局过滤器和内部过滤器全局过滤器定义在vue实例化之前 内部过滤器注册在实例内部,仅在...

  • Vue.js备忘记录(四) vue过滤器文本格式化, 插槽 sl

    一. vue过滤器 //文本格式化 Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化。 过滤器可以用...

  • vue.js过滤器的基本使用

    过滤器分为两种: 全局过滤器 自定义过滤器 使用过滤器,我们可以对数据进行格式化处理 具体代码 代码解析: 全局过...

网友评论

      本文标题:vue全局过滤器 格式化时间

      本文链接:https://www.haomeiwen.com/subject/cgqevhtx.html