在React Native中从一页共享数据到另一页

时间:2018-12-01 19:57:19

标签: react-native

我试图在React Native中将数据从一页共享到另一页,它显示TypeError:null不是一个对象(正在评估'this.state.urltest')

Login.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button, TouchableOpacity} from 'react-native';
import { Actions } from 'react-native-router-flux';
export default class Login extends Component {
     urltest = 'https://www.google.com'
     testFunction = (str)=>{ 
        return 'https://www.google.com';
     }
  render() {
    return (
      <View style={styles.container}>
 <Button 
  title="Connect"
  color="#841584"
  accessibilityLabel="Learn more about this purple button"
   onPress={Actions.connectWebView}
   /> 
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#455a64',
  },

});

ConnectWebView.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button, TouchableOpacity, WebView} from 'react-native';
import { Actions } from 'react-native-router-flux';
import Login from './Login';

  export default class ConnectWebView extends Component {
    _onNavigationStateChange(webViewState){
        console.log(webViewState.url)
      }
  render() {
    return (
<WebView
       ref="webview"
       source={{uri: this.state.urltest}}
       onNavigationStateChange={this._onNavigationStateChange.bind(this)}
       javaScriptEnabled = {true}
       domStorageEnabled = {true}
       startInLoadingState={false}
     />
    );
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#FFFFFF',
  },

});

按钮单击以在React Native中将数据从一页共享到另一页,它显示TypeError:null不是对象(正在评估'this.state.urltest')。请检查上面的代码。

0 个答案:

没有答案