-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 在组件中怎么访问到根实例? #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
vue
vue
Comments
通过 this.$root |
无限循环调用$parent直到没有这个属性为止 |
楼上是假尤大? |
服 |
不是有一个this.$root吗? |
666 |
你不嫌麻烦吗 |
$root 看看源码 // 初始化生命周期相关的属性,以及为$parent,$child属性赋值
function initLifecycle (vm) {
var parent = options.parent
// ......
vm.$root = parent ? parent.$root : vm; // 如果没有父组件,根组件就是自己,如果有父组件,就取父组件的$root。
// ......
} 每个组件都会执行 initLifecycle,初始化自己的生命周期函数,并设置自己的$parent, $child, $root属性 会先从根组件,从上而下初始化,根组件没有父组件,$root 是自己。 它下面的组件都取父组件的$root ,所以都会取到根组件的实例 |
哈哈哈哈哈 |
🐂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[vue] 在组件中怎么访问到根实例?
The text was updated successfully, but these errors were encountered: