DEV Community

sium_hossain
sium_hossain

Posted on

2

How to call a method or trigger a function from one component to another in Nuxt

I need trigger a function from one component to another. I don't know it's necessary or not . But whatever here is the solution for you -

Suppose two component. One of them we can called A component and another can be called as B component- So I will trigger A component function from B component.

In component A-

created() {
        this.$root.$refs.A = this;
    },

// and here is the method which I called from `B` component
methods:{
      print(){
        // your others function logic
        console.log('A component function called')

    },
Enter fullscreen mode Exit fullscreen mode

And Now I called this print function from B component via a function.

In component B -

methods:{
  printFromA(){
        this.$root.$refs.A.print();
    }

}
Enter fullscreen mode Exit fullscreen mode

voila!!! check your console 😇
Thank You.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs