vue反向代理
vue中创建vue.config.js文件,代码如下
module.exports = {
// vue项目中关闭eslint
lintOnSave: false,
// 打包问题
publicPath: './',
outputDir: 'dist',
// 打包问题
runtimeCompiler: true, //关键点在这
devServer: {
// 默认打开服务器
open: true,
proxy: {
'/api': {
target:'填写的地址', //目标服务器
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': '' //重定向
}
}
},
}
}
使用中
this.$http.get("/api/getTime").then((res) => {
console.log(res);
});
main.js
import axios from 'axios'
Vue.prototype.$http = axios