I am working with 2 components:
- parent component (using vue-bootstrap modal with a vue-bootstrap table)
- child component (utilizing vue-bootstrap modal with a form)
Issue: When I submit the form in the child component, it successfully adds the object to the parent table array. However, the problem arises when I reset the form as it also resets the object in the table array, causing confusion. I have tried both push
and concat
methods without success.
Parent variable:
MA02_E_tb // table array [{descr_forn: '',fornitore:'',n_oda:''},{descr_forn: '',fornitore:'',n_oda:''}]
data() {
return {
form: {
descr_forn: 'prova',
fornitore:'prova',
n_oda:'prova',
}
},
methods: {
resetModal() {
this.form.descr_forn = '',
this.form.fornitore = '',
this.form.n_oda = '',
},
onSubmit: function(evt) {
evt.preventDefault()
this.$parent.MA02_E_tb = this.$parent.MA02_E_tb.concat(this.form)
},
Result:
MA02_E_tb = [{descr_forn: 'prova',fornitore:'prova',n_oda:'prova'}]
Upon reopening the child modal and resetting the form object with the resetModal
method, the result changes to:
MA02_E_tb = [{descr_forn: '',fornitore:'',n_oda:''}]
form = [{descr_forn: '',fornitore:'',n_oda:''}]
The confusing part is why does it reset MA02_E_tb
even though it's a different variable?