1.新建文件vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': { //匹配路径
target: 'https://api.imjad.cn/cloudmusic/',//跨域目标
pathRewrite: {
'^/api' : '/'//重新地址
}
},
'/search': {
target: 'https://v1.alapi.cn/api/music/',
pathRewrite: {
'^search': '/'
}
}
}
}
}
使用axios访问跨域的数据
mounted: async function() {
let res = await axios.get("/api", {params:{id: 26222428}});
console.log(res);
this.res = res.data.data[0];
}