Subscribe on changes!

assignment an new value to reactive object in onMounted lifecycle(script setup)

avatar
Nov 3rd 2021

Version

3.2.20

Reproduction link

sfc.vuejs.org/

Steps to reproduce

1 using script setup;
2 in onMounted hook, modify array object width array.map method, then assignment to reactive object

What is expected?

myList is reactive

What is actually happening?

myList dosn't reactive


none

avatar
Nov 3rd 2021

it seems can not assignment to reactive object in onMounted hook

avatar
Nov 3rd 2021

sorry to interrupt, may be i should do like this

const data =reactive( {
  mylist: []
})
onMounted(() => {
  data.myList = []
})
avatar
Nov 3rd 2021

You should use a ref() instead so you can replace the whole value.


Remember to use the forum or the Discord chat to ask questions!

avatar
Nov 4th 2021

You should use a ref() instead so you can replace the whole value.

Remember to use the forum or the Discord chat to ask questions!

thank you very much! i wondering why use ref(.value) or reactive(reference) design, but i didn't find answer in rfcs issues, can you give me some tips?