axios 设置请求头内容

axios设置请求头中的Authorization信息:

GET请求

this.$axios.get('/url', 
    {
        headers: {
            'Authorization': 'Bearer '+localStorage.getItem('token')
            ...
        },
        params: {
            param1: string,
            param2: string
        },
        ...
    }
)
.then(res => fn)
.catch(err => fn)

POST请求

axios.post(urlString, 
    {
        data: data,
        ...
    },
    {
        headers: {
            'Authorization': 'Bearer ' + token
            ...
        }
    }
)
.then(res => fn)
.catch(err => fn)
原文地址:https://www.cnblogs.com/zhaohui-116/p/12346442.html