Avoid mutating a prop directly since the value will be overwritten

前端 未结 11 920
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 01:07

I have very common problem with upgrading to Vue 2.0

I am getting warning:

Avoid mutating a prop directly since the value will be overwritte

11条回答
  •  忘掉有多难
    2020-12-10 01:56

    I'm not sure what exactly you want to achieve but I'll take two options out of it.

    First one: It's all about getting rid of this warning.

    data () {
      return {
        childVal: this.parentVal
      }
    }
    

    Second one: You want to communicate between parent and child.

    If I got it right, this is a basic example of an in a child component communicating with its parent.

    Parent HTML:

    {{ user }}

    Parent JS:

    data () {
      return {
        user: 'John'
      }
    }
    

    Child HTML:

    
    

    Child JS:

    props: ['value']
    

    Working example: http://jsfiddle.net/kf3aLr1u/

    You can also read more about it in the docs https://vuejs.org/v2/guide/components.html.

提交回复
热议问题