12

I have a repository (in a MenuRepository.js file) that has an index() method, when I try to call that method from my mounted() function in my Vue instance, I get the following error

enter image description here

This has been working before, So I can't imagine what happened.. This is the code of my Vue instance.

class MenuRepository {
  async index () {
    const result = await Nova.request().get('/')
    return result.data
  }
}

export default MenuRepository

And this is the Vue file

import MenuRepository from '../repositories/MenuRepository'

export default {
  async mounted () {
    try {
      const menus = await MenuRepository.index()
    } catch (err) {
      console.error(err)
    }
  }
}
1
  • 2
    index is an instance method, however you are calling it on the class not an instance of the class. Unless I am missing something I think you should either make index static or create a new instance of the class, depending on what your intention is. Commented Mar 11, 2019 at 10:00

1 Answer 1

3

Solution

The issue was that it wasn't being instantiated.

Use

export default new MenuRepository()

Instead of

export default MenuRepository
Sign up to request clarification or add additional context in comments.

1 Comment

this way the module exports a "singleton" object. I'd advise instead making the index() function static or calling the constructor in your code importing the module: const menus = await new MenuRepository().index()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.