Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Axios承诺链接不起作用_Javascript_Axios - Fatal编程技术网

Javascript Axios承诺链接不起作用

Javascript Axios承诺链接不起作用,javascript,axios,Javascript,Axios,我正在尝试使用调用ApicCalls并使用promise的ApicClient,但我发现错误: "Cannot read property of 'then' of undefined" 我希望ApicCalls仅“返回”我已修改或从服务器获得的数据,并且ApicClient能够在我的代码中的某个地方调用: const apiClient = new ApiClient() apiClient.getCharacterOrders(character.character_id, charac

我正在尝试使用调用ApicCalls并使用promise的ApicClient,但我发现错误:

"Cannot read property of 'then' of undefined"
我希望ApicCalls仅“返回”我已修改或从服务器获得的数据,并且ApicClient能够在我的代码中的某个地方调用:

const apiClient = new ApiClient()

apiClient.getCharacterOrders(character.character_id, character.access_token)
然后,当它被处理时,我将通过事件发送它。但是ApicClient从不从ApicCalls“return”获取数据


通过在HTTP.get前面添加“return”并删除“this.response”解决了这个问题,因为它返回response.data.data

Probaste只返回HTTP.get()?其中的内容。/axioClient`?
getCharacterOrders
不返回任何内容。在HTTP.get(…)之前添加
return
。默认情况下,没有
return
语句的函数返回
undefined
(因此出现错误“无法读取undefined的'then'属性”
ApiClient file
-----------------------------------------------

import ApiCalls from './ApiCalls'

const apiCalls = new ApiCalls()

class ApiClient {

  getCharacterOrders (characterId, accessToken) {

    apiCalls.getCharacterOrders(characterId, accessToken)
      .then(response => {

        this.response = response.data

        console.log('Response ' + this.response)

        // Send this via an event somewhere

      }).catch(e => {
        this.errors.push(e)      
      })

  }
}

export default ApiClient




ApiCalls file
-----------------------------------------------


import {HTTP} from './axiosClient'

class ApiCalls {
  getCharacterOrders (characterId, accessToken) {
    HTTP.get('/characters/' + characterId + '/orders/?token=' + accessToken)
    .then(response => {

      this.response = response.data

      // Do stuff to data here

      return this.response

    }).catch(e => {
      this.errors.push(e)      
    })
  }

}

export default ApiCalls