首页 > 解决方案 > 我不想要,但是当在 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' 复制到它

标签: vue.jsdatevuexmutationvue-i18n

解决方案


推荐阅读