How to update reactive Objects (and properties in general)?

后端 未结 2 1664
耶瑟儿~
耶瑟儿~ 2021-01-15 15:52

Vue.js documentation on Reactivity in Depth mentions that

a property must be present in the data object in order for Vue to convert it and make it r

2条回答
  •  离开以前
    2021-01-15 16:25

    This is because in the first case, you are running a setter on tags (because you are reassigning it) - which Vue has wrapped and can detect. In the second case, you're running setters on nested properties that were not in your data: { tags: { definition, so they are not reactive.

    The Change Detection Caveats section in the documentation covers this, though not exactly the same as your case (the nested properties situation). You would have to declare your data like:

    data: {
      tags: {
        hello: null,
        world: null,
      }
    }
    

提交回复
热议问题