我在 localhost 和 Server 上对对象分配有不同的行为

问题描述

为什么 Object.assign 在本地主机上工作正常,但在服务器上却没有?

我的 vue 应用托管在 S3 上,除了 Object.assign 之外,一切正常。

远程 api 被正确调用并且更新正常,但是对象没有被分配并且我在捕获中得到一个错误。 console.log(JSON.stringify(e)) 的日志只是 {}。

      axios
        .put(this.url + "/client/" + item.id,{
          name: item.name,contactName: item.contactName,phoneNumber: item.phoneNumber,email: item.email,})
        .then((response) => {
          Object.assign(this.client[this.editedindex],item);
        })
        .catch((e) => {
          console.log(JSON.stringify(e));
          this.dialogError = true;
        });
    },

我尝试过像这样 Object.assign({},this.client[this.editedindex],item); 一样更改对象分配,但我遇到了任何意外行为。

解决方法

您得到的错误很可能是由 import * as widgets from 'survey-widgets export default widgets 的空值引起的。看看下面的例子:

this.client[this.editedIndex]

印刷品:

(new Promise((resolve) => { resolve(); }))
  .then(() => { 
    console.log('then'); 
    Object.assign(undefined,{a: 1}); 
  })
  .catch((e) => { 
    console.error('error',JSON.stringify(e)) 
  });

then error {} 替换 undefined 给出了类似的结果。因此,我假设您的 null 处的 this.client 键没有价值。

在错误记录中,您应该避免将 JSON.stringify() 与 Error 实例一起使用,因为 JSON.stringify 不知道如何处理它:

this.editedIndex

您正在丢失所有信息 - 例如消息、堆栈等。