React native 在Press React Native上找不到变量

React native 在Press React Native上找不到变量,react-native,React Native,我是新手,我尝试在按钮的onPress方法中运行一个简单的函数,但当我尝试加载按钮所在的页面时,返回错误“找不到变量‘test’” 这是密码 import React from 'react'; import { Layout, Button, Text } from 'react-native-ui-kitten'; export default class Settings extends React.Component { test(){ fetch('http://19

我是新手,我尝试在按钮的onPress方法中运行一个简单的函数,但当我尝试加载按钮所在的页面时,返回错误“找不到变量‘test’”

这是密码

import React from 'react';
import { Layout, Button, Text  } from 'react-native-ui-kitten';

export default class Settings extends React.Component {

test(){
      fetch('http://192.168.100.160:3000/prenotazioni')
        .then(response => response.json())
        .then(users => console.warn(users))
}

render(){
  return (
  <Layout style={{flex: 1, alignItems: 'center', justifyContent: "center"}}>
    <Text>Sei nelle Settings</Text>
    <Button onPress={test}>MySQL</Button>
  </Layout>
  );
}
}
从“React”导入React;
从“react native ui kitten”导入{Layout,Button,Text};
导出默认类设置扩展React.Component{
测试(){
取('http://192.168.100.160:3000/prenotazioni')
.then(response=>response.json())
.then(用户=>console.warn(用户))
}
render(){
返回(
赛内尔设置
MySQL
);
}
}

使用
onPress={this.test}

添加
onPress={this.test}
。如下图所示:

从“React”导入React;
从“react native ui kitten”导入{Layout,Button,Text};
导出默认类设置扩展React.Component{
建造师(道具){
超级(道具);
//此绑定是使`This`在回调中工作所必需的
this.test=this.test.bind(this);
}
测试(){
取('http://192.168.100.160:3000/prenotazioni')
.then(response=>response.json())
.then(用户=>console.warn(用户))
}
render(){
返回(
赛内尔设置
MySQL
);
}
}
试试
this.test()