美文网首页
vue-cli下跨域 问题的解决方法

vue-cli下跨域 问题的解决方法

作者: 18fa100a8459 | 来源:发表于2018-05-31 18:17 被阅读0次

链接地址

目的:使用vue-cli构建的项目,在开发时,想要访问后台接口获取数据,               这时就会出现跨域问题。

在config/index.js中进行如下配置

proxyTable: {

    ‘/api’: {

        target: ‘https://188.188.18.8‘,

        changeOrigin: true,

        pathRewrite: {

            ‘^/api’: ”

        }

    }

}

vue-resource调用示例

this.$http.get('/api/v4/user/login', [options]).then(function(response){

    // 响应成功回调

}, function(response){

    // 响应错误回调

});

axios调用示例

axios({

method: 'get',

headers: {'Accept': '*/*'},

url: '/api/v4/user/login',

data: options

})

.then(function (response) {

console.log(response.data)

})

.catch(function (error) {

console.log(error)

})

相关文章

网友评论

      本文标题:vue-cli下跨域 问题的解决方法

      本文链接:https://www.haomeiwen.com/subject/ymtmwxtx.html