【发布时间】:2020-07-01 18:31:06
【问题描述】:
我有一个带有 props 的组件,我想将值从 false 修改为 true,但我有一个消息表单 chrome 控制台
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders
在父组件中,我有一个函数(myFunction),它接受一个参数(值)。
我需要像这样保持我的论点,但我还需要从子组件中检索 emit 的值以更改 myData 的值而不改变子组件中的道具。
https://codesandbox.io/s/distracted-wiles-w8vwf
<template>
<div>
<p>The number is {{number}}</p>
<Child :MyProp="myData" @on-click-btn="myfonction(5)"/>
</div>
</template>
<script>
import Child from "./components/Child.vue";
export default {
data() {
return {
myData: 'button',
number: 1
};
},
components: {
Child
},
methods: {
myfonction(value) {
this.number = value;
}
}
};
</script>
谢谢
【问题讨论】:
-
这能回答你的问题吗? Vue 2 - Mutating props vue-warn
-
不抱歉,谢谢
-
你能分享代码吗,你在哪里遇到这个错误?
-
我更新了我的代码。
标签: javascript vue.js