一、在main.js中,封装获取当前时间的方法
Vue.prototype.$getTime = function() {
let time = new Date()
let year = time.getFullYear()
let month = time.getMonth() + 1
let day = time.getDate()
if(month < 10) {
month = '0' + month
}
if(day < 10) {
day = '0' + day
}
return year + '-' + month + '-' + day + ''
}
二、在组件中调用
this.$getTime()