我正在尝试更新包含文件数据的对象的某些属性。目前,我通过一个动作触发我的突变
const payload = { attachment, isUploading: true }
this.$store.dispatch('updateTempAttachment', payload)
您可以在我传递文件的有效负载中看到,以及我想要更新的值。如果我查看这个对象的状态,我会看到类似这样的内容
tempAttachments:Array[1]
0:Object
_id:"12345"
bytes:0
content:"File Upload by Select or Drop"
extension:".vnd.ms-excel"
file:File
fileType:null
hasErrors:false
headers:Array[0]
isUploaded:false
isUploading:false
key:3339843
progress:0
size:3337529
thumb:undefined
thumb_list:undefined
title:"file.csv"
type:"file"
在我的突变中,我正在这样做
UPDATE_TEMP_ATTACHMENT (state, payload) {
const match = state.tempAttachments.filter(item => item.id === payload.attachment.id)[0]
Object.keys(payload)
.forEach(function eachKey (key) {
if (key !== 'attachment') {
match.key = payload[key]
}
})
}
所以首先我想找到与 id 匹配的状态的文件。然后我想为附件以外的任何其他数据循环负载。然后我想将匹配的属性设置为有效负载中的内容。
目前我似乎收到错误
TypeError: Converting circular structure to JSON
显然,如果我对此进行硬编码,我可以做类似的事情
match.isUploading = true
但是在整个上传过程中我需要更新不同的内容,因此尝试动态执行此操作。
感谢任何帮助