-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 如何在子组件中访问父组件的实例? #477
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
Comments
this.$parent |
this.$parent拿到父组件实例 |
this.$parent |
vue中如果父组件想调用子组件的方法,可以在子组件中加上ref,然后通过this.$refs.ref.method调用(https://www.cnblogs.com/jin-zhe/p/9523029.html) |
$refs也行 |
子组件访问父组件:$parent 但少用 $parent 和 $children 它们主要用来应急,更推荐用 props 和 events 实现父子组件通信 如果子组件是公共组件,到处用,你在当前这个父组件下用没问题,但在别的地方用这个子组件,你还需要 $parent 吗?$parent 有对应的属性或方法吗?很容易产生bug,不利于调试。 所以这种写法是不被推荐的,官方文档有写。 |
this.$emit |
[vue] 如何在子组件中访问父组件的实例?
The text was updated successfully, but these errors were encountered: