javascript - nuxt.js 中 asyncData 中属性的奇怪强制
问题描述
我正在尝试在 Nuxt.js 中使用 asyncData,但在我看来,并非每个属性都可以按原样放置在这里。例如 Moment (moment.js) 和 DateTime (luxon) 的实例,它们被序列化为字符串:
import { DateTime } from 'luxon'
const moment = require('moment')
...
asyncData(context) {
return {
date1: moment(),
date2: DateTime.local(),
pureDate: new Date()
}
},
mounted() {
console.log(typeof this.date1) // string ("2019-06-11T16:24:00.746Z")
console.log(typeof this.date2) // string ("2019-06-13T19:24:00.748+03:00")
console.log(typeof this.pureDate) // object (Thu Jun 13 2019 19:24:00 GMT+0300 (Moscow Standard Time))
}
其他一些复杂对象属性引发警告:
Cannot stringify arbitrary non-POJOs OpenPositions
有人请向我解释这种行为
解决方案
推荐阅读
- ruby-on-rails - Ruby on Rails 如何获取表格特定列的每一行?循环遍历行?
- r - 从数据框中计算每日参数,其中包含行中的每小时值和几列感兴趣的列
- bash - 如何在单引号内转义双引号内的变量?
- java - 无法发送显示 SocketException 的 post https 请求:连接重置
- leaflet - 如何使用 Leaflet 和 L.Control.ListMarkers 从列表中获取悬停元素上的标记弹出窗口?
- c - Is there any problem while returning the "char pointer" from function
- php - 使 mysql 查询适应 mssql
- java - move xml namespace declarations to root element with jax-ws annotations
- vba - NOT的奇怪行为
- python - Pythonic way to get the max difference between any 2 consecutive elements of a list