I am new to vuejs and I am trying to sync active data to parent but getting an error as
vue.js:523 [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: "active" (found in component )
My Vuejs Code is as below
<div id="app">
<pre>
{{$data}}
</pre>
<div v-for="plan in plans">
<plan :plan="plan" :active.sync="active"></plan>
</div>
</div>
<template id="mytemplate">
<div>
{{$data}}
<span>{{plan.name}}</span>
<span>{{plan.price}}</span>
<button @click="setActivePlan">upgrade</button>
</div>
</template>
<script src="vue.js"></script>
<script>
new Vue({
el: "#app",
data: {
active:this.active,
plans: [
{name: 'Diamond', price: '1000'},
{name: 'Gold', price: '500'},
{name: 'Silver', price: '250'},
{name: 'Free', price: '0'}
]
},
components: {
plan: {
template: "#mytemplate",
props: ['plan', 'active'],
methods: {
setActivePlan: function () {
this.active = this.plan
}
}
}
}
});
</script>
Can any one help me to solve this