在axios的请求中添加代理配置以解决API被阻止的问题。具体步骤如下所示:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://example.com',
changeOrigin: true
}
}
}
}
其中,/api为被阻止的API地址,target为代理的API地址,changeOrigin为true时将主机头的原点更改为目标URL。
axios.get('/api/user').then(response => {
console.log(response.data);
});
在实际使用时,将proxy和target字段改为相应的API地址和代理地址即可。