When starting a new project, you can use the following command:
npm init nuxt-app <project-name>
To set up the baseURL for axios, refer to this guide:
npm install @nuxtjs/axios
In your nuxt.config.js file:
modules: [
'@nuxtjs/axios',
],
axios: {
baseURL: 'http://localhost:9000',
},
publicRuntimeConfig: {
axios: {
browserBaseURL: process.env.BROWSER_BASE_URL
}
},
privateRuntimeConfig: {
axios: {
baseURL: process.env.BASE_URL
}
},
To make API calls in pages/post.vue, use the following code:
axios.get('/posts')
If you are unable to call the server on port 9000, you can change the base URL to port 3000 where nuxt.js is running. Update
axios.defaults.baseURL = 'http://localhost:9000'
in pages/post.vue
to access it correctly.