Socket
Socket
Sign inDemoInstall

@nuxtjs/axios

Package Overview
Dependencies
3
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nuxtjs/axios

This plugin is a wrapper around [axios](https://github.com/mzabriskie/axios). It tries to resolve and make easier lot's of ajax tasks specially with SSR. So you can use **$get('profile')** instead of `(await Axios.get('http://server/api/profile')).data`.


Version published
Weekly downloads
168K
increased by1.48%
Maintainers
1
Install size
333 kB
Created
Weekly downloads
 

Readme

Source

Axios

This plugin is a wrapper around axios. It tries to resolve and make easier lot's of ajax tasks specially with SSR. So you can use $get('profile') instead of (await Axios.get('http://server/api/profile')).data.

  • Uses optionally custom URL when executing requests in server-side.
  • Handles all HTTP exceptions and prevents server side unhandled promise exceptions.
  • Injects $get,$post,... into vue context instances so requests can be done out-of-the-box.
  • Exposes setToken function so we can easily and globally set authentication tokens.
  • Returns empty object if request fails.
  • Throws nuxt-friendly exceptions if needed.
💡 Usage
  • Add axios module
import {$get} from '~/nuxt-modules/axios';

async data() {
    let {profile} = await $get('profile');
    return {profile}
}

Or In any other function: (This does not needs importing axios plugin)

mounted() {
    let {profile} = await this.$get('profile');
    return {profile}
}

Customization

Customization can be done using shared environment variables.

Environment variableDefaultDescription
API_URLhttp://localhost:3000Base url for ajax requests in server-side
API_URL_BROWSER[API_URL]Base url for ajax requests in client-side
API_PREFIX/apiAdds this prefix before all relative urls

FAQs

Last updated on 10 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc