nuxt-3-axios
v1.3.5
Published
Axios in Nuxt 3
Downloads
232
Maintainers
Readme
Axios in Nuxt 3
Axios in Nuxt 3 with batteries included for doing amazing things.
Features
Now you can get typed axios instance inside your nuxt app from Nuxt context
nuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-3-axios'
],
axios:{
baseURL: 'https://swapi.dev/api/'
//options to pass Axios Config
}
})
Example.vue
const { $axios } = useNuxtApp()
const result = await $axios.get('/people/1')
// result = {
// "name": "Luke Skywalker",
// }
Quick Setup
- Add
nuxt-3-axios
dependency to your project
# Using pnpm
pnpm add -D nuxt-3-axios
# Using yarn
yarn add --dev nuxt-3-axios
# Using npm
npm install --save-dev nuxt-3-axios
- Add
nuxt-3-axios
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-3-axios'
],
axios:{
//options to pass to axios create https://axios-http.com/docs/instance
baseURL: 'https://swapi.dev/api/'
}
})
That's it! You can now use Axios in Nuxt 3 in your app ✨
Development
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release