下载:npm install axios
main中引用:Vue.prototype.$http = axiosimport axios form “axios”
分为get和post
./寻找的是根目录
this.$http.get("地址",{传递参数})
.then(()=>{成功以后的指令})
.catch(()=>{失败})
.then(()=>)
post请求:
post请求不支持自己的服务器!!!
还需要下载 cnpm i qs -S
由于post传参的特殊性,所以在main中引入:import qs from 'qs';Vue.prototype.$qs = qs;
后台请求会出现跨域问题:
解决跨域的办法:
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');