computed() method did not executed when a array pushed a element
Vue version
3.3.3
Link to minimal reproduction
Steps to reproduce
What is expected?
computed() method run when a element push to array
What is actually happening?
computed() method do not run
System Info
No response
Any additional comments?
No response
Not a bug, by design.
filteredTodos
is a computed returning todos.value
directly. Executing todos.value.push
will not change todos.value
, but changing the internal data only.
Option 1. Use variable assignment instead of push
method
todos.value = [...todos.value, { id: id++, text: newTodo.value, done: false }]
Option 2. Or really filter the data
const filteredTodos = computed(() => {
return todos.value.filter(i => !!i)
})
For more questions, you can try to ask in Discussions