React Native WebView uses local HTML files

React Native WebView uses local HTML files

. Note that the local file path is: http://localhost:8081/iosPages/b.html

 

HTML file /iosPages/b.html: 

<h1>this is a html file</h1>
<p>this is content hello </p>

 

JS file:

'use strict';
var React = require('react-native');
where {
  StyleSheet,
  Text,
  View,
  WebView,
} = React;

var App = React.createClass({
  getInitialState: function () {
    return ({
        content: '',
    });
  },
  render: function() {
    return (
      <View style={{flex:1, marginTop:60}}>
        <WebView html={this.state.content} automaticallyAdjustContentInsets={false} />
      </View>
    );
  },
  componentDidMount: function () {
    let url = 'http://localhost:8081/iosPages/b.html';
    fetch(url)
      .then((response) => response.text())
      .then((responseText) => {
        this.setState( {content: responseText});
      })
      .catch((error) => {
        console.warn(error);
      });
  },

});

module.exports = App;

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043995&siteId=291194637