Vue CLI Axios Integration Plugin

0.0.4 · abandoned · verified Sun Apr 19

The `vue-cli-plugin-axios` package is a small, specific plugin designed to integrate the Axios HTTP client into projects scaffolded with Vue CLI 3. Released at a very early version (0.0.4) and last published over five years ago, this plugin is considered abandoned. It aimed to simplify global Axios access within Vue 2 applications by injecting `$axios` or `Vue.axios` onto the Vue instance or prototype. However, its relevance is significantly diminished as Vue CLI itself is now in maintenance mode, with new Vue projects (both Vue 2 and Vue 3) encouraged to use Vite via `create-vue`. Modern Vue 3 projects typically integrate Axios by directly installing the `axios` package and importing it explicitly where needed, or by manually attaching it to `app.config.globalProperties` as a custom plugin. There are also actively maintained wrapper libraries like `vue-axios` (version 3.x.x for Vue 3, 2.x.x for Vue 2) that provide similar global injection capabilities for contemporary Vue ecosystems. This specific `vue-cli-plugin-axios` package does not offer any distinct advantages over direct Axios integration or current wrapper libraries for modern development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the typical installation command for a Vue CLI plugin and how `this.$axios` would be used in a Vue component after the plugin globally attaches Axios. It also shows a modern, manual global Axios setup for Vue 3, as the plugin itself is deprecated.

import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

// Assuming vue-cli-plugin-axios was added to a Vue CLI 3 project (Vue 2 or 3 compatible at the time)
// This plugin typically modifies `main.js` or creates a plugin file like `src/plugins/axios.js`.
// The core part of the plugin injects Axios globally.

// Example of what the plugin would achieve (simplified representation):
import axios from 'axios';

const app = createApp(App);

// If using Vue 2 with this plugin, it would be Vue.use(Plugin, axios)
// For Vue 3, if the plugin were updated, it might use globalProperties
// (This specific plugin is for Vue CLI 3, often used with Vue 2, or early Vue 3 setup)

// Manual global Axios setup for modern Vue 3 (alternative to old plugin):
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$http = axios;

app.use(store);
app.use(router);
app.mount('#app');

// Example component usage in a .vue file (Options API for Vue 2, compatible with plugin's intent):
/*
<template>
  <div>
    <button @click="fetchData">Fetch Data</button>
    <pre>{{ responseData }}</pre>
  </div>
</template>

<script>
export default {
  data() {
    return {
      responseData: null,
      error: null,
    };
  },
  methods: {
    async fetchData() {
      try {
        const result = await this.$axios.get('https://jsonplaceholder.typicode.com/todos/1');
        this.responseData = result.data;
      } catch (e) {
        this.error = e;
        console.error('Error fetching data:', e);
      }
    },
  },
};
</script>
*/

view raw JSON →