[Vuejs]-Vue/Vuex: Implicitly pass object to all children

0๐Ÿ‘

I wrote a small recursive function for you which any of the children component can call which goes through the hierarchy of parent to find the parent with certain attribute and return that attribute value to caller. You just need to add additional checks to prevent any deadman loops.

export function findParentAttrValue(parent: any, attr: string): string {
  if (parent[`${attr}`]) {
    return parent[`${attr}`];
  } else {
    return findParentAttrValue(parent.$parent, attr);
  }
}

Leave a comment