Skip to content
Advertisement

Vue.js : Passing an external variable to a component through initialization?

I am trying to pass a variable (here, externalVar) to a component, directly when initializing. But I can’t find how to do it (probably not understanding documentation well :/ ). What is the correct way to do it?

The initialization :

JavaScript

The component I am initializing here is defined like this (getting back variableToPass in data):

JavaScript

But then , when I am trying to use this.jsonObject, it says that it’s undefined. What am I doing wrong ?

Advertisement

Answer

If i understand you correctly you want to use props to pass data to child components

Dynamically bind a prop attribute on child component element using :variable="variableToPass"

JavaScript

Define a props option in the child component

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement