解决跨域问题

解决跨域问题,第1张

跨域问题

协议,域名,端口号不一致

项目根目录新建vue.config.js

module.exports = {
    devServer:{
        open:true,

        // host:'localhost',

        // port:8080,

        // https:false,

        // hotOnly:false,

        proxy:{
            '/api':{
                target:"http://web.juhe.cn",

                changeOrigin:true,

                pathRewrite:{
                    '^/api':''

                }

            }

        }

    }

}

定义全局变量

Vue.prototype.HOST = '/api'

HOST添加到请求方法中

————————————————
版权声明:本文为CSDN博主「思念至极」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_67573138/article/details/124792721

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/944604.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-18
下一篇2022-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存