This is my root element, and in the data "booking" is a object with sitebooking. Sitebooking object can have array of objects with first name and last name.
var app = new Vue({
el: '#app',
data: {
booking: {
sitebooking: [{
firstname: "",
lastname: ""
},{
firstname: "",
lastname: ""
}],
}
}
});
And this is my template (child component),
<template id="sitebooking_template">
<div>
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group required">
<label for="firstname">First name</label>
<input class="form-control" placeholder="First name" required="" name="firstname" type="text" value="" id="firstname" v-model="newcompsitebooking.firstname">
</div>
</div>
<div class="col-md-6">
<div class="form-group required">
<label for="lastname">Last name</label>
<input class="form-control" placeholder="Last name" required="" name="lastname" type="text" value="" id="lastname" v-model="newcompsitebooking.lastname">
</div>
</div>
</div>
</div>
</template>
And i am looping through booking.sitebooking object in parent compoent to create multiple child component (each site booking will get one child component).
<div class="" id="app">
<sitebooking v-for="(val,idx) in booking.sitebooking" :key="idx" :my-sb="val"></sitebooking>
</div>
I am passing the value through "my-sb" props and assinging in to local data in the child component.
Vue.component('sitebooking', {
template: '#sitebooking_template',
props:["mySb"],
data: function () {
return {
newcompsitebooking : this.mySb,
}
}
});
Till now everything works, but the strange behavior is whenever I change the value in the child component, it updates the data of parent component too. But according to vuejs documentation, the change in child component will be propagated back to parent via emit. But i am not emitting data back to parent, but still the value updates automatically in parent.
Can anyone pls help on this?