已获取高德天气为例, 不过这里还没有用到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);
        })

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐