美文网首页ReactNative笔记
RN笔记-WebView加载Url和本地静态html标签

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

作者: 金丝楠 | 来源:发表于2017-02-21 16:18 被阅读70次

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

相关文章

网友评论

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

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