0

As the way of injecting API and call API by nuxt alias like this post NuxtJS - manage several axios instances

It is working well with vue file or middleware.

But since I create new folder in src is service for managing API, I can't call alias of API anymore.

-src
 -plugins
  -api.js
 -services
  -user.js

in file user.js, I use alias to call API but it does not work ($nuxt.$api)

user.js

export default {
  async getUser(payload) {
    return await $nuxt.$api.get('/user/', {
      headers: {
         Authorization: `Bearer ${payload}`
      }
    })
  }
}

Any suggestion for my issue. Thank for your help.

Hai Tien
  • 2,556
  • 7
  • 32
  • 49
  • 1
    Does this answer your question? You need to pass an instance of the Nuxt context in to your user.js method. https://stackoverflow.com/questions/66960906/access-nuxt-config-within-vuex-state/66961849#66961849 – Nick Dawes May 03 '22 at 15:04

0 Answers0