ReactNative笔记

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

2017-02-21  本文已影响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>
    )},

上一篇 下一篇

猜你喜欢

热点阅读