我设法使用axios来执行带标题的GET请求
fetchUsers = ({offset = 1, q = ''} = {}) => new Promise(function (resolve, reject) {
const url = `localhost:3000/users`
axios.get(url, {
headers: { token: 123 }
}).then(response => {
})
})
但我也想要分页和搜索的可选查询参数,我做
fetchUsers = ({offset = 1, q = ''} = {}) => new Promise(function (resolve, reject) {
const url = `localhost:3000/users`
axios.get(url, {params: {offset, q}}, {
headers: { token: 123 }
}).then(response => {
})
})
我不再在标题中看到我的令牌,任何线索?
答案 0 :(得分:0)
我认为,您应该尝试使用params将标题移动到对象:
axios.get(url, {params: {offset, q},
headers: { token: 123 }}