Vue | 基于 vue-admin-template 项目的跨域问题解决方法
vue-admin-template
PanJiaChen/vue-admin-template: 基于 Vue.js 和 Element UI 的后台管理系统模板,支持多语言、主题和布局切换。该项目提供了一个完整的后台管理系统模板,可以方便地实现后台管理系统的快速搭建和定制,同时支持多种数据源和插件扩展。
项目地址:https://gitcode.com/gh_mirrors/vu/vue-admin-template
免费下载资源
·
目录
自存
一、现存问题
报错截图如下:
二、解决方法
2.1 修改的第一个地方
在 .env.development 文件中:
# base api
# VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://18.137.108.102:8080' # 修改为服务器地址
2.2 修改的第二个地方
在 vue.config.js 文件中:
module.exports = {
devServer: {
// before: require("./mock/mock-server.js"),
proxy: {
"/api": {
target: process.env.VUE_APP_BASE_API,
changeOrigin: true, // 配置跨域
pathRewrite: {
"^/api": "",
},
},
},
},
}
也就是注释掉原有的 “before” 那一行,然后再添加后面的代码。
2.3 修改的第三个地方
在 /utils/request.js 文件中:
// create an axios instance
const service = axios.create({
// baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
baseURL: "/api", // 只需要修改这个位置
// withCredentials: true, // send cookies when cross-domain requests
timeout: 5000, // request timeout
});
GitHub 加速计划 / vu / vue-admin-template
16
5
下载
PanJiaChen/vue-admin-template: 基于 Vue.js 和 Element UI 的后台管理系统模板,支持多语言、主题和布局切换。该项目提供了一个完整的后台管理系统模板,可以方便地实现后台管理系统的快速搭建和定制,同时支持多种数据源和插件扩展。
最近提交(Master分支:4 个月前 )
4c18a3f4 - 3 年前
714ded11 - 4 年前
更多推荐
已为社区贡献5条内容
所有评论(0)