1.解决跨域访问失败
在项目的根目录下创建一个 vue.config.js 文件
- 创建配置文件
module.exports = {
devServer: {
proxy:{
'/api' : {
target : "http://cdn.apc.360.cn",
ws : true,
pathRewrite : {
'^/api' :''
}
},
"/imgList" : {
target : "http://cdn.apc.360.cn",
ws : true,
pathRewrite : {
'^/imgList' :''
}
}
},
},
};
- 使用
// 把代理的名字 放在请求路径的前面
getClassData() {
this.$axios
.get(
"/api/index.php"
)
.then((res) => {
this.classList = res.data.data;
});
},