Vue的axios使用说明

下载axios:

npm install axios --save

导入axios:

import axios from "axios";

Vue.prototype.$axios = axios;
//必写
axios.defaults.baseURL = "/api";
//代表发送端发送的实体数据的数据类型
axios.defaults.headers.post["Content-Type"] = "application/json";

在根目录创建一个名字为 "vue.config.js " 文件:

module.exports = {
    publicPath: "/",
    outputDir: "dist",
    assetsDir: "static",
    filenameHashing: true,
    lintOnSave: true,
    runtimeCompiler: false,
    devServer: {
        open: process.platform === "darwin",
        host: "0.0.0.0",
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: {
            "/api": {
                target: "https://localhost/",
                changeOrigin: true,
                secure: false,
                pathRewrite: {
                    "^/api": ""
                }
            }
        }
    }
};

引入外部css:

 

你可能感兴趣的:(vue3.0)