RN笔记-WebView加载Url和本地静态html标签

WebView的使用非常简单,本文提供加载Url和本地静态html标签(Div层)的使用方法,贴出代码供以后学习使用。

加载Url
var Shop = React.createClass({
  render() {
    return (
      <View style={styles.container}>
        <WebView
          automaticallyAdjustContentInsets={true}
          javaScriptEnabled={true}
          domStorageEnabled={true}
          decelerationRate="normal"
          startInLoadingState={true}
          contentInset={{top:-110, bottom:-64}}
          source={{url:'https://h5.ele.me/shop/#geohash=wtsqjxd22cuxczqysbpmrq&id=317562'}}/>
      </View>
    );
  },
});
加载本地静态html标签
// 静态html标签例子
var html = '<!DOCTYPE html><html><body><h1>This is a heading!</body></html>';

var HtmlDetail = React.createClass({
  render() {
    // alert(this.props.html);
    return(
      <View style={styles.container}>
        {this.renderNavBar()}
        <WebView
          // automaticallyAdjustContentInsets={true}
          // 关键在这里
          source={{html:this.props.html}}
          // javaScriptEnabled={true}
          // domStorageEnabled={true}
          // decelerationRate="normal"
          // startInLoadingState={true}
          />
      </View>
    )},

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容