axios发送数据带headers
发送post 带headers,post请求基本格式,axios.post(url[, data[, config]])。其中,url表示请求的API接口地址,data是请求的参数,config是请求的配置项,如超时时间、请求头。已获取高德天气为例, 不过这里还没有用到header, 参数都在params中。
·
已获取高德天气为例, 不过这里还没有用到header, 参数都在params中
export function getWeatherInfo(cityCode) {
let url = `https://restapi.amap.com/v3/weather/weatherInfo`
return new Promise((resolve, reject) => {
axios.get(url, {
params: {
key: '高德key',//请求参数
extensions: 'base',
output: 'json',
city: cityCode
}
}).then(res => {
return resolve(res.data)
}).catch(res => {
return reject(res)
})
})
}
发送post 带headers, post请求基本格式,axios.post(url[, data[, config]])。其中,url表示请求的API接口地址,data是请求的参数,config是请求的配置项,如超时时间、请求头。
axios.post(url, data, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Token': 'Bearer ' + token
},
}).then((res) => {
console.log('beginvideo res->', res);
})
更多推荐
已为社区贡献2条内容
所有评论(0)