当我尝试使用@click
指令更改道具的值时,我收到此警告:
[Vue warn]: 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"
我的代码如下:
<html>
<head>
<title>Vue test</title>
</head>
<body>
<div id="app">
<user-name name="Flavio"></user-name>
</div>
<script src="assets/js/vue.js"></script>
<script type="text/javascript">
Vue.component('user-name', {
props: ['name'],
template: '<p @click=bio1()>Hi {{ name }}</p>',
methods: {
bio1(){
this.name = "Caleb";
}
}
})
new Vue({
el: "#app"
})
</script>
</body>
</html>
这个警告的原因是什么?