axios.get和post设置请求头区别
作者:互联网
使用axios.get设置headers时,下面的写法可行,后端能接收到数据。但是axios.post不能使用这种方法。
new Vue({ el: '#login', user: { account: "", password: "" }, created: function () { axios.post("http://localhost:8080/", {//错误示范 headers: { 'jwt': jwt } }).then(r => { }) } } );
正确方法:
headers:{'jwt':jwt}还需要大括号括起来
methods: { doLogin: function () { axios.post('http://localhost:8080/login', { headers:{'jwt':jwt} }, //正确 { account: this.user.account, password: this.user.password }).then(r => { }) } }
标签:axios,get,jwt,headers,user,post,password 来源: https://www.cnblogs.com/wsy1996/p/16578225.html