
Vue.prototype.$getFutureDate = function (val) {
var now = new Date()
var nowMs = now.getTime()
var beforeMs = nowMs + 1000 * 60 * 60 * 24 * parseInt(val)
var beforeDate = new Date().setTime(beforeMs)
var year = new Date(beforeDate).getFullYear()
var month = new Date(beforeDate).getMonth() + 1
var date = new Date(beforeDate).getDate()
var years = year < 10 ? '0' + year : year
var months = month < 10 ? '0' + month : month
var dates = date < 10 ? '0' + date : date
return years + '-' + months + '-' + dates
}
截图并复制了代码,为方便使用。此方法绑定在了Vue的原型链上。
本文介绍了一个实用的Vue方法,用于获取未来的日期。该方法通过在当前时间基础上增加指定天数来实现,返回格式化的日期字符串,便于在Vue应用中直接使用。
1436

被折叠的 条评论
为什么被折叠?



