美文网首页ReactNative
ReactNative Webview交互

ReactNative Webview交互

作者: Windows_XP | 来源:发表于2018-08-14 12:12 被阅读0次

RN 端:

    onMessage = (event) => {
        let paramArray=event.nativeEvent.data.split(',');
        
        //用户收取途链
        let params=new Map();
        params.set('telPhone',paramArray[0]);
        params.set('context',paramArray[1]);
        Http.write(2000,params,(promise)=> {
            promise.then(response => {
                this.refs.toast.show(response.message)
            }).catch(err => {
                //请求失败
                this.refs.toast.show(err)
            })
        })
    }
                <WebView
                    ref='webViewRef'
                    automaticallyAdjustContentInsets={false}
                    style={styles.webView}
                    source={{uri: ''}}
                    javaScriptEnabled={true}
                    domStorageEnabled={true}
                    decelerationRate="normal"
                    onNavigationStateChange={this.onNavigationStateChange}
                    onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}
                    // startInLoadingState={true}
                    scalesPageToFit={this.state.scalesPageToFit}
                    onMessage={this.onMessage}
                />

Web端:

<input type="button" onclick="toNative()" id="tjfk" value="提交意见">
    function toNative() {
        let context=window.document.getElementById('studyIdea').value;
        let phone=window.document.getElementById('phone').value;
        window.postMessage([context,phone]);
    }

相关文章

网友评论

    本文标题:ReactNative Webview交互

    本文链接:https://www.haomeiwen.com/subject/bknmbftx.html