1、main.js当中引入
// 引入个人定义js文件
import * as tools from './common/util/faser/useage.js'
// 自定义tools
Vue.prototype.$tools=tools;
2、在vue文件中引用:
{{$tools.getDateTime()}}
this.$tools.getDateTime()
3、工具类文件必须遵循格式:export function
useage.js中:
// 获取当天时间 日期。
export function getDateTime() {
let tmp = new Date();
let str = tmp.getFullYear() + '-' + tmp.getMonth()+1 + '-' + tmp.getDate() + ' ' + tmp.getHours() + ':' + tmp.getMinutes() + ':' + tmp.getSeconds()
return str
}