因为后端给的接口不是本地的接口,所以需要跨域来获取接口数据 在Vue.config.js中对其进行配置 devServer: { host: 'localhost',
因为后端给的接口不是本地的接口,所以需要跨域来获取接口数据
devServer: {
host: 'localhost',
port: 3030, // 端口
https: false,
proxy: {
// 配置跨域
'/api': {
target: 'Http://xx.xx.xx.xxx', // 代理的接口域名以及端口号;
ws: true, // 支持ws协议;websocket的缩写;
changeOrigin: true, // 是否跨域
pathRewrite: { // 路径替换
'^/api': '/api'
}
}
},
hotOnly: false,
before: app => {}
},
在axiOS.js中配置baseURL
let config = {
baseURL:'/api'
};
最后使用$axios来请求数据即可
mounted(){
this.$axios.get('index_cateGory/data').then((v)=>{
console.log(v);
})
}
成功后效果如下
以上就是vant/vue跨域请求解决方案的详细内容,更多关于vant/vue跨域请求解决方案的资料请关注编程网其它相关文章!
--结束END--
本文标题: vant/vue跨域请求解决方案
本文链接: https://www.lsjlt.com/news/175740.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0