18

I have a (parent) component in Vue that ships with it's own on-screen keyboard which is in it's own Vue component. The keyboard keeps track of the entered value and passes this value to the parent component. Sometimes the parent component needs to reset the value.

The way it is currently implemented is by directly modifying the prop that is passed to the keyboard. That obviously yields the warning Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders.. However, this is exactly the behaviour I expect in this case: The variables are in sync, and should stay in sync if the parent changes the value. In other words: I want to disable this specific warning for this specific component.

I could add a watcher to the property that overwrites a local variable and use the local variable instead to keep track of things. That's... silly, as it does exactly what it does now, with more variables to keep track of. I have however not found a way to squelch warnings yet. Is there such a feature?

Sumurai8
  • 19,483
  • 10
  • 67
  • 96
  • You don't even need a watcher: just use a computed property or an internal data store: http://stackoverflow.com/questions/39868963/vue-2-mutating-props-vue-warn – Terry May 12 '17 at 08:57
  • Both the parent and the child need access to the variable, and they can't access each others variables except through the prop/event system. With internal data store I guess you mean vuex's datastore? That seems overkill, as I don't want the value to persist beyond where the parent and child are actually displayed. – Sumurai8 May 12 '17 at 09:28
  • 1
    One way might be to pass the property as an object, with the relevant info as properties of the object. Vue won't complain because you're not mutating the reference to the object. – Bert May 12 '17 at 15:24

1 Answers1

13

As per Linux Borg (core dev) it is currently (Vue 2.5.17) not possible to disable any warnings on a per-component basis. You can use the Vue.config.silent option to silence all warnings.

Sumurai8
  • 19,483
  • 10
  • 67
  • 96