I'm currently working in a page with parent/child components. Somehow my child component gets updated when I manage its variables in the parent component. What I'm trying to do:
- My child component has a 'site' variable with all the data i need to send via API
- My parent component has a Save button to send the child data to the Back-end
- When 'site' changes in the child component, I'm emitting an event @changeto the parent component
- The @changeevent contains all the data I need, but not in the format I want
- There is a function submit()that gets this data and modify the one of the arrays so that this: ['foo','bar'] becomes this 'foo,bar'
- The problem when I do the step '5' my child component gets updated
The child component inside the parent component
<configuracoes :configuracoes="configuracoes" @change="setData"
      v-if="currentPage === 'configs'"/>
The change event emitted by the child component
this.$emit("change", this.site);
The important part of 'site' var
site: {
  seo: {
   keywords: [],
             ...
           },
          ...
    },
The setData() function
setData(data) {
    this.data = data;
},
The submitData() function
submitData() {
    if (this.currentPage === "configs") {
        let data = ({}, Object.assign(this.data))
        let keywords = data.seo.keywords.join(',')
        data.seo.keywords = keywords
        this.$store.dispatch("sites/updateSite", {
            empresa_id: this.user.empresa_id,
            site_id: this.siteId,
            dados: data,
        });
    }
}
As you can see, I'm declaring another variable let data to avoid updating this.site variable, but no success
 
    