ReactNative Webview交互

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)
            })
        })
    }
                

Web端:


    function toNative() {
        let context=window.document.getElementById('studyIdea').value;
        let phone=window.document.getElementById('phone').value;
        window.postMessage([context,phone]);
    }

你可能感兴趣的:(ReactNative Webview交互)