(复习)父子组件传值使用v-modal双向绑定,报错Avoid mutating a prop directly解决方案

报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent component........

原因:所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件中,但是反过来则不行。(父组件更新,子组件中的prop值也会更新,但子组件不能修改由父组件传递过来的值)

不能直接对父组件传来的值进行双向绑定,要先子组件里定义新的变量来接收父组件传来的值,接着我们可以使用v-modal+watch属性 或者 使用:binfd="" + @input=" func"(再定义这个func通过传入的event 得到改变的值,将event.target.value赋值给新变量)

11   
12

我是父组件

13 14 :num-from-father2="fatherData2" 15 @change1="changeFunc1" 16 @change2="changeFunc2"/> 17
18 19 32 33       

你可能感兴趣的:((复习)父子组件传值使用v-modal双向绑定,报错Avoid mutating a prop directly解决方案)