相对moment.js
而已,day.js
的体积更小,只有2KB左右;moment.min.js
有16.7KB。
- Day.js官方文档https://dayjs.fenxianglu.cn/category/#node-js
- Moment.js 官网http://momentjs.cn/Day.js 常用方法_dayjs_halo1416的博客-CSDN博客前言Day.js 是代替修改本地Date.prototype,Day.js对Date对象进行了封装,只需要调用Dayjs()即可。相对moment.js而已,day.js的体积更小,只有2KB左右;moment.min.js 有16.7KB。对应普通项目来说,对应时间的操作就只有那么几个(格式化、查询、计算),这些基于Day.js完全足够。并且Day.js的文档相对简单、清晰!该文章对比之前的moment.js的文章Day.js官方文档 当前文章很多实例是以当前时间来处理的, 当前时间https://blog.csdn.net/halo1416/article/details/124298324moment.js 的常用方法_halo1416的博客-CSDN博客vue项目中,需要把 moment.js 挂载到全局上(即vue的原型链上),访问时直接使用 this.moment() ;vue项目中不挂载到全局,单文件(单组件)使用: ==>> import moment from "moment"; 然后直接使用 moment()1. 初始化日期 / 时间初始化日期:moment().for...https://blog.csdn.net/halo1416/article/details/83620022
- vue项目中,需要把day.js或者 moment.js 挂载到全局上(即vue的原型链上),访问时直接使用this.day() 或者 this.moment() ;
-
// 引入day.js import dayjs from 'dayjs'; Vue.prototype.$dayjs = dayjs; // 例如 currentDate: this.$dayjs(new Date()).format('YYYY-MM-DD') // 引入moment.js import moment from "moment"; Vue.prototype.moment = moment; startTime: this.moment().subtract(1, "month").format("YYYY-MM-DD") endTime: this.moment().format("YYYY-MM-DD")