背景:
因为要接入迅雷链测试,所以要使用迅雷提供的API,肯定是涉及跨域了。
修改前的调用:
this.$http.post('https://sandbox-walletapi.onethingpcs.com/api/linktest/regist')
解决:
采用了最简单的方法,因为项目是用vue-cli搭建的,所以在项目配置文件中(config/index.js)开发环境下有个配置叫“proxyTable”,对其设置:
proxyTable: {
'/api': { // api为匹配项
target: 'https://sandbox-walletapi.onethingpcs.com/api', // 设置代理目标
changeOrigin: true,
pathRewrite: { // 重写路径
'^/api': '/'
}
}
},
修改后的调用:
this.$http.post('/api/linktest/regist')