const token=store.state.token //从store中取出的token
let para={
...
} //要传的参数
get
this.$axios.get("url",{
params:para,
headers:{'token':token}
}).then(...)
post
this.$axios.defaults.headers.common['token']=token
this.$axios.post("url",para).then(...)
tips:
get传入的是params,post传入的是data
get中也可单独写this.$axios.defaults.headers.common[‘token’]=token
post中如果写
this.$axios.post("url",{
data:para,
headers:{'token':token}
}).then(...)
会出错
post中如果写
this.$axios.defaults.headers.common['token']=token
this.$axios.post("url",{
data:para,
}).then(...)
也会出错