vue.js - 我不想要,但是当在 Vue 应用程序中更改计算属性中的日期区域设置时,我会在数组中发生状态突变
问题描述
我有带有 vueI18n 的 Vue 应用程序用于本地化。
在我的数组数据中,我有日期字符串(“2018-01-04T01:10:54.673Z”)。
我尝试根据我的语言环境更改此字符串。
前两次效果很好,但后来我收到一个错误([Vue warn]: Error in render: "RangeError: Invalid time value")对我来说很
清楚,由于字符串格式错误,在我原来的突变后状态。new Date()
怎么了???
store.js
getters: {
notes: state => state.notes
},
...
组件.vue
computed: {
...mapGetters(["notes"]),
getInfo() {
const info = Array.from(this.notes);
info.map(el => {
el.createdAt = this.$d(new Date(el.createdAt), "short", i18n.locale);
el.updatedAt = this.$d(new Date(el.updatedAt), "short", i18n.locale);
});
return info;
},
这个。是来自我的状态的 Console.log 它已使用上面的代码进行了更新
(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, __ob__: Observer]
0: 创建于:“2018 年 1 月 4 日”
这就是我从 API 0 得到的
:createdAt:"2018-01-04T01:10:54.673Z"
主要问题是为什么这个代码
info.map(el => {...}
改变我的状态???
我使用私有 const 信息
并将我的状态与 getter 'notes' 复制到它
解决方案
推荐阅读
- c# - 如何在 C# 中使用 QRCoder 在 QR 码下方添加文本?
- go - 你能告诉我golang通道缓冲区是如何工作的吗?
- c# - 关键字“Key”附近的语法不正确。ASP.net 详细信息视图中的错误
- assembly - 如何在 aarch64 gicv3 中读取中断状态(活动、挂起、活动挂起、..)?
- laravel - Laravel 8:路由寄存器上的数组到字符串转换
- sql - 加入后如何删除重复的元组?
- python - 如何在python中将整数更改为字符串?
- c# - 使用 linq 查询绑定表内时避免数据滞后问题
- python - 如何在 on_message 事件 discord.py 后触发我的机器人向用户发送消息
- javascript - 在 D3 中对导入的 CSV 文件的节点进行分组