【发布时间】:2021-04-08 19:55:12
【问题描述】:
我是 React Native 新手,请忽略我的英语
我创建了两个名为 Browse.js 和 Setting.js 的文件,我在 Browse.js 中编写了我的 API 函数,并从这些函数导航到 setting.js 和 setting.js。现在我想检查来自我在browse.js中声明的API的响应数据,并根据该数据我想呈现一个块。例如是 "title"="admin" 然后渲染这个。
这是我在 Browse.js 中的 API 函数 =
RoleLogin(){
// const { username, password, roles } = this.state;
fetch('https://jsonplaceholder.typicode.com/todos/1'
// fetch("https://nasdigital.tech/Android_API_CI/validate_login_details"
, {
method: "GET",
headers: { "Content-Type": "application/json" },
// body: JSON.stringify([{ username: username, password: password }]),
})
.then(response => response.json())
.then((json) => {
//login to check details from server and then display or navigate to another screen
// if (json != "error")
if (json != "error")
// if (response && response.length && response[0].message != "error")
{
alert(JSON.stringify(json));
this.props.navigation.navigate("Settings");
} else {
alert("Cehck Details");
}
})
.catch((error) => alert("Cehck Details"));
}
//*******************navagte to setting when data fetch close**************************** */
componentDidMount() {
this.setState({ categories: this.props.categories });
}
这是我在 Setting.js 中的块,如果 title='something' 或 role='admin' 我想呈现它
{title == " " &&
<Block row space="between" margin={[10, 0]} style={styles.inputRow}>
<Block style={{ flexDirection:'row'}}>
<Text gray2 style={{ marginBottom: 10 }}></Text>
<Foundation name="page-copy" size={24} color="black" />
<Text bold style={{paddingHorizontal: 20 }}>Customer Report</Text>
</Block>
</Block>
}
【问题讨论】:
-
能否提供相关代码?
-
是的,我已经更新了,请检查
标签: reactjs react-native native