Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
React native [TypeError:undefined不是对象(正在计算此.setState';)]_React Native_Axios_React Native Android - Fatal编程技术网

React native [TypeError:undefined不是对象(正在计算此.setState';)]

React native [TypeError:undefined不是对象(正在计算此.setState';)],react-native,axios,react-native-android,React Native,Axios,React Native Android,我对ReactNative和axios有问题。我想将响应URL保存在状态变量中,但我遇到以下问题: [类型错误:未定义不是对象(计算'this.setState')] 职能: githubGetUrl = () => { axios({ method: 'get', url: 'http://' + global.IP_ADDRESS + ':8080/github/link' }).then(function(response) {

我对ReactNative和axios有问题。我想将响应URL保存在状态变量中,但我遇到以下问题:

[类型错误:未定义不是对象(计算'this.setState')]

职能:

githubGetUrl = () => {
    axios({
      method: 'get',
      url: 'http://' +  global.IP_ADDRESS + ':8080/github/link'
    }).then(function(response) {
      this.setState({githuburl: response.data.LINK})
      console.log('Résultat [' + this.state.githuburl + ']')
    }).catch(function(error) {
      console.log(error)
    });
  }
}
建造商:

constructor (props) {
  super(props)
  this.state = {
    clicked: '',
    githuburl: ''
  }
}
我已经在网上搜索了,但是我没有找到问题的根源

如果有人能帮助我,我将不胜感激


谢谢

您可以尝试在
中使用箭头功能,然后

githubGetUrl = () => {
    axios({
      method: 'get',
      url: 'http://' +  global.IP_ADDRESS + ':8080/github/link'
    }).then((response) => {
      this.setState({githuburl: response.data.LINK})
      console.log('Résultat [' + this.state.githuburl + ']')
    }).catch(function(error) {
      console.log(error)
    });
  }
}

setState
是一个异步进程,因此将您的
console.log
作为回调。我该如何做?
this.setState({githuburl:response.data.LINK},()=>console.log('Résultat['+this.state.githuburl+'])