首先,我们先看看在项目中的报错。
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “name”
子组件不可修改父组件的值。因此可以在data里定义一个值获取父组件的值。当需要的时候,修改自定义的值即可。
有一个可爱的孩子,父母给他取名为陆议。
因此,新建页面parent.vue(父母),以及子组件son.vue(陆议)。parent.vue的主要代码码如下:
1 <template> 2 <view> 3 <son name="陆议"></son> 4 </view> 5 </template>