When using `v-for`, the contents of the array are overwritten, but not re-rendered.
Version
3.2.25
Reproduction link
Steps to reproduce
Version
3.2.25.
Phenomenon
After running, clicking new Game
will overwrite the temporaryInitArray
array, but the elements on the page are not re-rendered.
What is expected?
Rebuild according to the overwritten array.
What is actually happening?
Elements on the page are not rendered.
If I understand your code, temporaryInitArray
and temporarySolvedArray
are not reactive i.e. they are not wrapped in reactive
or ref
. If that's the case, it's the expected behavior.
A good start is converting temporaryInitArray
and temporarySolvedArray
to refs, like you did with difficulty
.
Something like this:
const temporaryInitArray = ref<string[]>([])
const temporarySolvedArray = ref<string[]>([])
[temporaryInitArray.value, temporarySolvedArray.value] = getUniqueSudoku(difficulty.value, difficulty.value)
function newGame() {
[temporaryInitArray.value, temporarySolvedArray.value] = getUniqueSudoku(difficulty.value, difficulty.value)
}
It seems like onUpdated
has an unrelated bug, too. You probably wanted to say:
onUpdated(() => {
newGame()
})
And perhaps some watchers are more suitable than onUpdated
.