【发布时间】:2020-06-29 19:03:45
【问题描述】:
我对 React Native webview 有疑问,我想我知道这个问题。在使用令牌填充令牌值之前,webview 正在运行?如何让 webview 在渲染前等待令牌?
我知道这是原因,如果我运行 auth api 并获取令牌并将其粘贴到“令牌”所在的位置,则 Web 视图会正确呈现。
代码:
const getSetData = async() =>{
await AsyncStorage.getItem('token').then((result) => {
token = result;
});
}
return (
<View styles={styles.container}>
<NavigationEvents
onDidFocus = {()=> {
getSetData();
}}
/>
<View style={{alignItems:'center', marginTop: 60}}>
<SLSHeader style={{height: 65, width: '100%'}} navigation={props.navigation} title="RAPID RATES"/>
<View style={{padding:10, top: 20, marginTop:40, marginBottom:10, width:'95%', height:'90%'}}>
<WebView
source={{uri: 'http://myurl.com', headers:{"Authorization":token} }}
style={{ width: '100%', height: '100%'}}
/>
</View>
</View>
</View>
);
【问题讨论】:
标签: reactjs react-native