vue3安装axios

npm i axios -S

新建api文件夹
api->axios.ts:

import axios from 'axios';
let instance = axios.create({
    baseURL: 'http://localhost:8080',
})
export default instance;

api->index.ts:

import { type } from "os";
import instance from "./axios";
export const loginHandle = (options: any) => {
    return instance({
        url: "/loginHandle",
        method: options.method,
        data: options.data,
    })
}
export default {
    loginHandle
};

使用

const options = {
   method: 'post',
   data: {
      user_name: 'admin',
      password: 'admin',
   }
}
loginHandle(options);

你可能感兴趣的:(vue3安装axios)