使用 day.js,使用 npm 安装:
npm install dayjs --save
1.执行安装依赖
//执行安装依赖
npm install dayjs --save
2.引入分为两种方法
第一个是在单文件里导入xxx.vue里面引入
import dayjs from 'dayjs'
第二个全局引入是在main.js里引用
//main.js引用
import dayjs from 'dayjs'
Vue.prototype.dayjs = dayjs// 全局使用dayjs
3.获取当前时间格式化
//获取当前时间格式化
let date = dayjs().format('YYYY-MM-DD') //年月日
let time = dayjs().format('HH:mm:ss'); //时间
4.搭配后端接口使用,将时间格式化传给后端,即可获取需要的数据
//搭配后端接口使用
let timeBegin = `${date} ${time}`
xxx接口({
id: id,
time: timeBegin ,//将时间格式化传给后端
}).then((res) => {
console.log(res) //即可获取需要的数据
})
作者上一篇文章,
本文详细介绍day.js的安装步骤及使用方法,包括通过npm安装、局部与全局引入方式,并展示了如何格式化日期时间,以及如何配合后端接口传递格式化的时间数据。
https://blog.youkuaiyun.com/weixin_43928112/article/details/127057885?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22127057885%22%2C%22source%22%3A%22weixin_43928112%22%7D
538

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



