Bump since I posted over the weekend.
Oct 23, 2022
3
Level 20
Vue3: Keep objects in array reactive
I'm adding an object to a reactive array, but when I update the object, I don't see the changes.
<script setup>
import { reactive, ref } from 'vue'
let key = ref(null)
let uploads = reactive([])
let uploadFile = (file) => {
let upload = {
key: key.value++
name: file.name,
type: file.type,
size: file.size,
state: 'uploading',
}
uploads.push(upload)
// Upload Logic...
upload.state = 'complete' // Doesn't work
}
</script>
This used to work in vue2, but to make this work in Vue3, you have to retrieve the object from the array first:
// Upload Logic...
upload = uploads[uploads.findIndex(el => el.key == upload.key)]
upload.state = 'complete' // Works
Is there any way to do this without having to retrieve the object each time?
Please or to participate in this conversation.