美文网首页
react native 中添加webview

react native 中添加webview

作者: _越努力_越幸运 | 来源:发表于2018-07-13 10:29 被阅读0次

1.在render中添加

<View>

<WebView

style={{height:300,width:300}}

ref={'webView'}

source={{uri: MAP_DATA_URL}}  //此处URL为服务器返回的html

javaScriptEnabled={true}

onLoadEnd={this.pageOnLoaded.bind(this)}

/>

</View>


2.在类中添加pageOnLoaded方法:

pageOnLoaded() {

    let data = {

      key:'app',

      url: 自己定义的url,//此处的url为请求服务器时的URL

        parameter:12,

 };//参数按照自己的需求去定义

          this.refs.webView.postMessage(JSON.stringify(data));//必须转化成字符型

  }

相关文章

网友评论

      本文标题:react native 中添加webview

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