React Native WebView使用本地HTML文件

React Native WebView使用本地HTML文件

这里注意本地的文件路径为:http://localhost:8081/iosPages/b.html

 

HTML文件 /iosPages/b.html: 

this is a html file

this is content hello

 

JS文件:

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

var App = React.createClass({
  getInitialState: function () {
    return ({
        content: '',
    });
  },
  render: function() {
    return (
      
        
      
    );
  },
  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;

 

你可能感兴趣的:(react-native)