vue .sync的使用

在使用vue的. sync中,怎么都用不出来。

出来错误:

I Avoid mutating a prop directly since the value will be overuritten whenever the parent component re-renders.

查资料,说的都是vue2以上,取消了.sync..只能在vue1以下用.

可官方的资料中可以用呀: .sync 修饰符.

官方的不可能有问题呀.

于是,按照官方的一步步下去,发现.sync可以使用.但是子组件中要写,这个一定要写的,一定要写一定要写一定要写

this.$emit('update:title', newTitle)

title是要在父组件中改变的变量.

这样一写的话,在父组件中,引用子组件,.sync就启作用了

<text-document :title.sync="title"></text-document>

I Avoid mutating a prop directly since the value will be overuritten whenever the parent component re-renders.

原文地址:https://www.cnblogs.com/ztgzlu/p/11142653.html