const dateformat = import('dateformat')
template.defaults.imports.dateformat = dateformat;
const html = template('xx.art',{
time:new Date()
})
报错
错误信息:RuntimeError: dateFormat is not a function]
解决:
不使用dateformat,用moment代替
在powershell里面下载 npm install moment
const moment = require('moment')
template.defaults.imports.moment = moment;
模板文件(xx.art)
{{ moment(time).format("YYYY-MM-DD HH:mm:ss") }}
本文讲述了在JavaScript中使用`dateformat`库时遇到的错误,并提供了使用moment.js替代的解决方案。作者介绍了如何在模板文件中通过moment.js格式化日期,展示了从问题到解决的全过程。
594

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



