You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
777 B
18 lines
777 B
5 months ago
|
// 获取父组件的参数,因为支付宝小程序不支持provide/inject的写法
|
||
|
// this.$parent在非H5中,可以准确获取到父组件,但是在H5中,需要多次this.$parent.$parent.xxx
|
||
|
// 这里默认值等于undefined有它的含义,因为最顶层元素(组件)的$parent就是undefined,意味着不传name
|
||
|
// 值(默认为undefined),就是查找最顶层的$parent
|
||
|
export default function $parent(name = undefined) {
|
||
|
let parent = this.$parent;
|
||
|
// 通过while历遍,这里主要是为了H5需要多层解析的问题
|
||
|
while (parent) {
|
||
|
// 父组件
|
||
|
if (parent.$options && parent.$options.name !== name) {
|
||
|
// 如果组件的name不相等,继续上一级寻找
|
||
|
parent = parent.$parent;
|
||
|
} else {
|
||
|
return parent;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|