使用proxyTable进行跨域API代理
// config/index.js
module.exports = {
dev: {
proxyTable: {
// 将所有以 /api 开头的请求通过 jsonplaceholder 代理
'/api': {
target: 'https://wangcch.cc',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
调用
this.$http.get('/api/demo').then(function(res){
console.log(res.data);
})
依赖
npm install vue-resource