Answer the question
In order to leave comments, you need to log in
Reactivity not quite working vue 3?
Good afternoon, I have a problem, I don’t understand why it doesn’t work:
function addFlags(db) {
let index=0
let newdb = []
db.forEach(item=>{
let tmpobj = Object.assign({},item)
tmpobj.__uniqID = index
index++;
newdb.push(tmpobj)
})
return newdb
}
export default {
props: {
'items': { type: Array, default: () => [] },
},
setup(props){
let copyDB=reactive(addFlags(props.filterExt(props.items)))
watch(props.items, ()=>{
copyDB = addFlags(props.items)
}, { deep: true })
const MyTables = computed({ get: ()=>{
return copyDB
} })
return {
MyTables,
copyDB,
}
},
}
Answer the question
In order to leave comments, you need to log in
We open the section of the documentation dedicated to reactivity, and read there that
Tracking the reassignment of local variables <...> will not work, such a mechanism simply does not exist in JavaScript. You can only track changes in the properties of objects.
copyDB.splice(0, copyDB.length, ...addFlags(props.items));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question