Search code examples
vue.jsvuejs2vue-component

Passing data between components VueJS2


I have a parent component, it receives a large json from the server, I need to parse it and pass it to the child components.

child components are connected like

  <child-comp />

i need to pass res.data from server json to child comp to use it in rendering and in methods How can i do this?


Solution

  • You can pass your data as a prop like this :

    <child-comp :myData="res.data" />
    

    And in you're child component define the prop like this :

    props: {
      myData: Object
    },
    

    See more in vue doc : https://vuejs.org/guide/components/props.html