首页 > 解决方案 > Vue 无法在数据选项中获取对象的值

问题描述

所以我有这样的数据选项

data() {
    return {
      userPayload: {
        description: '',
        languageCodes: [],
        facebookUrl: '',
        youtubeUrl: ''
      },
    }
  },

后来我应用了一些函数来填写数据中的每个属性。然后,当我想使用 handleSaveData() 提交数据时,我将这个 userPayload 对象传递给 axios,结果它只读取了描述属性的值。

handleSaveData() {
...
const userPayload = {
   description: this.userPayload.description,
   profile: {
     languageCodes: this.userPayload.languageCodes,
     facebookUrl: this.userPayload.facebookUrl,
     youtubeUrl: this.userPayload.youtubeUrl
   }
}

console.log(this.userPayload)
// this one contains value of all attributes

console.log(userPayload)
// this one only shows value of description attributes, while the others are empty string or empty array
// i expect it also return value of another attributes
// because i already access it with this.userPayload.{attributeName}

}

this.userPayload 值

用户有效载荷值

我已经尝试过 deepClone userPayload 对象,但它不起作用

标签: javascriptvue.jsfrontend

解决方案


推荐阅读