I have a component and want to add a click listener that runs a method in the parent template in Vue. Is this possible?
You can use $root
like this with vanilla Vue, but, If you use nuxt with vue that response won't work. Why? because $root
is nuxt itself. Let me show you an example:
this.$root.$children[1].myRootMethod()
$root
: As I said before, this is nuxt.
$children[0]
: this is nuxtloading.
$children[1]
: this is your main component, in my case, it was a basic layout with a few global components and a global mixin.
$children[n]
: other components on your app.
Hope it helps.