简体   繁体   English

在Vue实例中混合反应性和非反应性数据是否有害?

[英]Can mixing reactive and non-reactive data in a Vue instance be harmful?

I have a Vue.js instance with its set of data predefined at initialization time. 我有一个Vue.js实例,它的data集是在初始化时预定义的。

vm = new Vue ({
  el: "#root",
  data: {
    x: 3
  }
})

I need to add, in the course of the script, a new element in data . 我需要在脚本过程中在data添加一个新元素。 It does not matter for me that it not reactive . 对我而言,它没有反应无关紧要

vm.y = 4

Is there an issue with such an action? 这样的动作有问题吗? Specifically, can this impact the Vue instance behaviour (beside the non-reactivity aspect for this member)? 具体来说,这是否会影响Vue实例的行为(除了该成员的非反应性方面)?

Note: this update is done before sending data elsewhere and it is just more convenient to update it on the fly without making an intermediate copy (which is certainly a possibility, should the above update be somehow harmful) 注意:此更新是在将data发送到其他地方之前完成的,它是在不进行中间副本的情况下即时更新它的更为方便的方法(当然,如果上述更新在某种程度上是有害的,这是有可能的)

Is there an issue with such an action? 这样的动作有问题吗? Specifically, can this impact the Vue instance behaviour (beside the non-reactivity aspect for this member)? 具体来说,这是否会影响Vue实例的行为(除了该成员的非反应性方面)?

This is perfectly fine, it will not interfere with how the component works, nor will Vue delete the property at some point (or anything like that). 很好,这不会干扰组件的工作方式,Vue也不会在某个时候(或类似的东西)删除该属性。 The only pitfall is that the property will not be reactive. 唯一的陷阱是该属性将不会发生反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM