Miguel Stevens
Miguel Stevens

Reputation: 9191

Webpack Imported Module is not a function

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)
    }
  }
}

Upvotes: 11

Views: 31255

Answers (1)

Miguel Stevens
Miguel Stevens

Reputation: 9191

Solution

The issue was that it wasn't being instantiated.

Use

export default new MenuRepository()

Instead of

export default MenuRepository

Upvotes: 3

Related Questions