Skip to main content

Vue axios

install

npm install axios

configuration

Add axios as global property in a vue js app in the main.js file :

import axios from "./axios";
app.config.globalProperties.$axios = axios;

To configure axios, create axios.js file in /src folder containing :

import axios from "axios";

axios.defaults.baseURL = "http://localhost/<app-name>/api";

export default axios;

if your php application served with ths webserver :

  • xampp: <app-name> is the folder name in /opt/lampp/htdocs

Example : /opt/lampp/htdocs/portfolio , the <app-name> is portfolio

  • httpd: <app-name> is the folder name in /var/www/html

Example : /var/www/html/portfolio , the <app-name> is portfolio