getParentAttr.js 345 B

123456789101112131415161718
  1. // 使用时,node = this.$parent;
  2. export default function getParentAttr(name, keys,node) {
  3. let parent = node;
  4. while (parent) {
  5. // 父组件
  6. if (parent.$options?.name !== name) {
  7. // 如果组件的name不相等,继续上一级寻找
  8. parent = parent.$parent;
  9. } else {
  10. return parent[keys];
  11. }
  12. }
  13. return undefined;
  14. }