currently i am trying to do a reset to initial data that is being loaded. Any help is appreciated.
html:
<div id="app">
<input v-model="name" type="text">
<input v-model="year" type="text">
<div v-for="group in groups">
<input v-model="group.group_name" type="text">
<input v-model="group.remarks" type="text">
</div>
<button @click="reset">Click to reset</button>
</div>
vue js:
const groups = [
{
group_name: 'group1 name',
remarks: 'group1 remarks'
},
{
group_name: 'group2 name',
remarks: 'group2 remarks'
}
];
const Example = Vue.extend({
data() {
return{
name: 'Creator',
year: 0,
groups: groups,
group: {
group_name: '',
remarks: ''
}
}
},
methods: {
reset () {
Object.assign(this.$data, this.$options.data.call(this));
}
}
});
new Example({
el: '#app',
mounted () {
setTimeout(() => this.year = 2001, 1000);
}
});
when the button triggers the reset function, only the name and year gets reset. how do i get the "group in groups" input to reset as well?