VueJS access child component’s data from parent

In my child component, there are no buttons to emit changed data. It’s a form with somewhat 5~10 inputs. the data will be submitted once you click the process button in another component. so, I can’t emit every property when it’s changing.

So, what I did,

In my parent component, I can access child’s data from “ref”

e.g

<markdown ref="markdowndetails"></markdown>
<app-button @submit="process"></app-button>

// js
methods:{
    process: function(){
        // items is defined object inside data()
        var markdowns = this.$refs.markdowndetails.items 
    }
}

Note: If you do this all over the application I suggest move to vuex instead.

Leave a Comment