学无先后,达者为师

网站首页 Vue 正文

vue3 开发调试阶段,本地解决api请求跨域的问题!

作者:wanmeifengfeng 更新时间: 2022-04-04 Vue

根目录下的vue.config.js文件配置下面没有备注的内容,如果没有vue.config.js文件可以手动创建一个复制下面代码!

module.exports = {
    // outputDir: 'dist',   //build输出目录
    // assetsDir: 'assets', //静态资源目录(js, css, img)
    // lintOnSave: false, //是否开启eslint
    devServer: {
        // open: true, //是否自动弹出浏览器页面
        // host: "localhost", 
        // port: '8081', 
        // https: false,   //是否使用https协议
        // hotOnly: false, //是否开启热更新
        // proxy: null,
		 proxy: {
		            '/ea55_api': {
		                target: 'http://127.0.0.1:8085/index.php', //API服务器的地址
		                ws: true,  //代理websockets
		                changeOrigin: true, // 虚拟的站点需要更管origin
		                pathRewrite: {   //重写路径 比如'/api/aaa/ccc'重写为'/aaa/ccc'
		                    '^/ea55_api': ''
		                }
		            }
		        },
    }
}

原文链接:https://blog.csdn.net/wanmeifengfeng/article/details/115767984

栏目分类
最近更新