[Vuejs]-How can I implicitly pass data to all child components in Vue?

0👍

From child component you can get parent component property like

this.$parent.myProp

https://vuejs.org/guide/components.html#Parent-Chain

Edit: Create function to find property in parents:

getProperty: function(vueComp, propName) {
    var p = vueComp.$parent;
    while (p) {
        if(p.hasOwnProperty(propName)){
        return p[propName];
        }
      p = p.$parent;
    }

    return null;
}

Use it like: var x = getProperty("myProp");

Leave a comment