0
点赞
收藏
分享

微信扫一扫

TS当中的跨域操作

夕颜合欢落 2022-03-12 阅读 13

当前端地址与后端服务地址不一样时,你可能需要的是跨域
首先找到vue.config.js文件
跨域操作:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {                
    port: 8080,	//前端访问的端口	不写默认为8080
    proxy: {                 
        '/api': {             //拦截器 名字自己定义
        //浏览器访问http://localhost:8080会被替换为http://localhost:8888  
            target: 'http://localhost:8888',     //需要代理的地址
            changeOrigin: true,             
            pathRewrite: {         
//浏览器访问http://localhost:8080/api/auth/xxx会被替换为http://localhost:8888/xxx 下面同理
                '^/api/auth': ''  ,                   
                '^/api': ''  , 
            }
        }
    }
}
})

举报

相关推荐

0 条评论