javascript - I've got different behavior for object assign on localhost vs Server
问题描述
Why the Object.assign works fine on Localhost but on server it does not ?
My vue app is hosted on S3 and everything works fine besides the Object.assign.
The remote api is being called properly and the update is ok, but the object is not being assigned and I got an empty error in the catch. log for console.log(JSON.stringify(e)) is just {}.
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;
});
},
I have tried change the object assign like this Object.assign({}, this.client[this.editedIndex], item);, but I got any unexpected behavior.
解决方案
您得到的错误很可能是由 的空值引起的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
的this.editedIndex
关键没有任何价值。
在错误记录中,您应该避免将 JSON.stringify() 与Error实例一起使用,因为 JSON.stringify 不知道如何处理它:
> JSON.stringify(new Error('message'))
'{}'
您正在丢失所有信息 - 例如消息、堆栈等。
推荐阅读
- java - 在没有根变量的二叉树中获取根
- amazon-web-services - aws s3 cp 一个命令中的多个文件
- java - 如果元素不显示,如何获取带有硒的文本?
- laravel - 如何在 laravel 中构建具有更多动态页面的项目
- javascript - 上传文件时出错:@using Html.BeginForm
- c# - EF 只包含一次嵌套实体
- c# - Asp.net core:如何通过 404 状态码获取错误页面中的原始路径
- stored-procedures - 用于显示多行的 Teradata 存储过程
- java - 从Android应用内摄像头拍照并将其上传到服务器的更有效方法
- git - 从 git-show 输出中提取提交消息的正文