RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
vue-cli跨域代理配置
参考了好多网上文章 配置代理总是不生效 ,其实不是配置的问题 是在调用的时候出的问题
把完整的调用过程整理下来希望可以帮助其他有疑惑的小伙伴
    例如 服务地址是 http://192.168.0.125/test/login 的调用过程

1 找到config ->index.js文件 配置proxyTable参数
        proxyTable: {
                '/api': {
                    target: 'http://192.168.0.125/test',
                    changeOrigin: true,
                    pathRewrite: {
                        '^/api': '/'
                    }
                }

                /api 代替的是 ' http://192.168.0.125/test'

    2 工具 封装
        const service = axios.create({
            timeout: 1000 * 30,
            withCredentials: true,
            baseURL:'/api/',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            }
        })

    3 action调用
        // 登录
        export function login (params) {
            return request({
                url:'login',
                method: 'post',
                data: requestParam(params)
            })
        }

当前题目:vue-cli跨域代理配置
文章出自:http://sczitong.cn/article/jhhopp.html