Glenn
Glenn

Reputation: 5051

Call a Vue method from outside the Vue app (Vue Webpack CLI)

I need to call a method from outside my app. I am using the Vue CLI. My method is in a component and looks something like this:

export default { 
  name: 'home',
  ...
  methods: {
    theMethodINeedToCall() {
      // does stuff
    }
  }

I have been searching for a way to access theMethodINeedToCall(). It's not hard to get there when you're not using the Vue CLI, but with the CLI, I can't seem to find my way there.

Upvotes: 2

Views: 2152

Answers (1)

Vamsi Krishna
Vamsi Krishna

Reputation: 31352

If the method has nothing to do with the component it's better you host the method outside of the component

At last component is just an object ,just import the component where yo want and call the method;

import MyComponent from './path/'

MyComponent.methods.theMethodINeedToCall();

Upvotes: 4

Related Questions