小菜又鸟
2022-03-14 16:22
采纳率: 83.3%
浏览 135
已结题

封装axios后返回的数据是undefined

没封装前可以返回数据:

  axios({
      url: `https://m.maizuo.com/gateway?filmId=${this.$route.params.id}&k=930931`,
      headers: {
        'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16466636386676260373659649","bc":"110100"}',
        'X-Host': 'mall.film-ticket.film.info'
      }
    }).then(res => {
      console.log(res)
      this.filmInfo = res.data.data.film
    })

封装后就无法返回数据了:

    http({
      url: `/gateway?filmId=${this.$route.params.id}&k=930931`,
      headers: {
        'X-Host': 'mall.film-ticket.film.info'
      }
    }).then(res => {
      console.log(res.data.data.films)
      this.datalist = res.data.data.film
    })

这是封装的axios:

import axios from 'axios'
const http = axios.create({
  baseURL: 'https://m.maizuo.com',
  timeout: 1000,
  headers: {
    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16466636386676260373659649"}'
  }
})

控制台结果就只有:
undefined

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题