Subscribe on changes!

When using `v-for`, the contents of the array are overwritten, but not re-rendered.

avatar
Feb 10th 2022

Version

3.2.25

Reproduction link

github.com

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.

avatar
Feb 10th 2022

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.

avatar
Feb 10th 2022

So what should I do? I really don't know anything about this.

avatar
Feb 10th 2022

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.

avatar
Feb 10th 2022

Thank you very much for your help and will correct these ridiculous mistakes.