图库网,天津三本院校,沧海一粟客栈
在axios向后端传参时需要设置请求头,确保请求参数的格式为json字符串(此时用json.stringify(obj)无效时)
this.$axios({ method:'', url:'', headers: { 'content-type': 'application/json',//设置请求头请求格式为json 'access_token': this.token //设置token 其中k名要和后端协调好 }, params:{} }).then((response)=>{})
下面看下axios设置请求头内容
axios设置请求头中的authorization 和 cookie 信息:
get请求
axios.get(urlstring, { headers: { 'authorization': 'bearer ' + token, "cookie" : 'sessionid=' + sessionid + '; recid=' + recid, ... }, params: { param1: string, param2: string }, ... } ) .then(res => fn) .catch(e => fn)
post请求
axios.post(urlstring, { data: data, ... }, { headers: { 'authorization': 'bearer ' + token, "cookie" : 'sessionid=' + sessionid + '; recid=' + recid, ... } } ) .then(res => fn) .catch(e => fn)
总结
以上所述是小编给大家介绍的vue-axios 设置请求头问题,希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
详解element上传组件before-remove钩子问题解决
vue.js中使用微信扫一扫解决invalid signature问题(完美解决)
网友评论