目录
vue跨域问题
/    

vue跨域问题

设置代理

修改config/index.js

proxyTable: {
            '/api': {
                target: 'http://127.0.0.1:8989', //目标接口域名
                changeOrigin: true, //是否跨域
                pathRewrite: {
                    '^/api': '/' //重写接口
                }
                /* 
                这里理解成用‘/api’代替target里面的地址,

                                    后面组件中我们掉接口时直接用api代替

                                    比如我要调用'http://127.0.0.1:8989/xxx/duty?time=2017-07-07 14:57:22',

                                    直接写‘/api/xxx/duty?time=2017-07-07 14:57:22’即可
                */
            }

        },

请求的时候,直接使用自己域名请求就行。


标题:vue跨域问题
作者:gitsilence
地址:https://blog.lacknb.cn/articles/2020/05/15/1589536859838.html