失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Vue使用Axios实现http请求以及解决跨域问题

Vue使用Axios实现http请求以及解决跨域问题

时间:2020-09-16 05:47:22

相关推荐

Vue使用Axios实现http请求以及解决跨域问题

参考:/p/3ab216fa185c

axios快速使用

示例demo

Vue使用Axios实现http请求以及解决跨域问题

引入qs 库

cnpm install qs

vue2.0下axios实现跨域踩的坑

VUE axios 跨域问题 No 'Access-Control-Allow-Origin' header is present on the requested resource.

cnpm install qs----------组件.vue-----------import axios from 'axios'import qs from 'qs';var data = qs.stringify({timeType:'Month',pointId:'40,30,31,34,39,43,35,29,38,26,27,28,36,41,42,32,33',startTime:'-4',endTime:'-4',dtBiDuiYear:'',factor:'a34052',});axios.post('/GetCompareData', data).then(function (response) {console.log(response.status);console.log(response.data);}).catch(function (error) {console.log(error);});---------config/index.js 转发代理-------proxyTable: {'/GetSoilTypeInfo':{ // 要代理的接口名target:'要转发的接口', // 要代理的接口地址changeOrigin:true, // 允许跨域 pathRewrite:{'^/GetSoilTypeInfo':''} // 接口名重写},'/GetTreeListForSoilByRegion':{ // 要代理的接口名target:'要转发的接口', // 要代理的接口地址changeOrigin:true,// 允许跨域pathRewrite:{'^/GetTreeListForSoilByRegion':''} // 接口名重写},'/GetCompareData':{ // 要代理的接口名target:'要转发的接口', // 要代理的接口地址changeOrigin:true,// 允许跨域pathRewrite:{'^/GetCompareData':''} // 接口名重写}},

如果觉得《Vue使用Axios实现http请求以及解决跨域问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。