以格式化时间方法为例

plugins文件夹下新建文件commom.js,添加如下代码

import Vue from 'vue'
var utils = {
  install(Vue) {
    Vue.prototype.utils = {
      formatDate: function(time, format = 'YY-MM-DD hh:mm:ss') {
        var date = new Date(time)

        var year = date.getFullYear(),
          month = date.getMonth() + 1, //月份是从0开始的
          day = date.getDate(),
          hour = date.getHours(),
          min = date.getMinutes(),
          sec = date.getSeconds()
        var preArr = Array.apply(null, Array(10)).map(function(elem, index) {
          return '0' + index
        }) ////开个长度为10的数组 格式为 00 01 02 03

        var newTime = format
          .replace(/YY/g, year)
          .replace(/MM/g, preArr[month] || month)
          .replace(/DD/g, preArr[day] || day)
          .replace(/hh/g, preArr[hour] || hour)
          .replace(/mm/g, preArr[min] || min)
          .replace(/ss/g, preArr[sec] || sec)

        return newTime
      }
    }
  }
}
Vue.use(utils)

nuxt.config.js里  添加

plugins: [
    ...
    { src: '~/plugins/commom.js', mode: 'client' }  //常用工具方法
  ],

页面中使用

this.utils.formatDate(new Date().getTime()) //2020-6-13 16:43:43
this.utils.formatDate(new Date().getTime(),'YY年MM月DD日');//2020年06月13日
this.utils.formatDate(new Date().getTime(),'今天是YY/MM/DD hh:mm:ss');//今天是2020/06/13 16:43:43