I am working on VueJS app that allows to edit json file with specific data. I have two similar components: AliasEntry and EquipmentEntry. The second is used to manipulate array of objects and seems to work fine. I can add, delete and edit fields. But AliasEntry, which serves arrays of aliases (strings) behaves weird and crashes: When I click on input with actual string in it and edit it, changes are updated in props. But when i click out of input, it's content is replaced by "[object Event]" and performing any action crashes app with error "Failed to execute 'structuredClone' on 'Window': Event object could not be cloned."
Here is code of AliasEntry component
<template>
<div>
<input
:value="item"
@input="(event) => handleAliasUpdate(event)"
>
</div>
</template>
<script>
import { toRaw } from 'vue'
export default {
props: {
item: String
},
methods: {
handleAliasUpdate(event){
const record = structuredClone(toRaw(event.target.value))
this.$emit('change', record)
}
}
};
</script>
I tried to add toRaw, because it helped earlier, but i am at loss right now. Note: i suppose this error ("Failed to execute 'structuredClone'...) happens in containing component.
It seems like the issue might be related to how you're handling the event object in your
handleAliasUpdatemethod.Use
event.target.valuedirectly withouttoRaw, sinceevent.target.valueis already the raw value you want.Remove the
structuredClonefunction, as it's unnecessary in this context and might be causing the error.You can do it like this:
I hope this helps you.