React Native WebView使用本地HTML文件
React Native WebView使用本地HTML文件
这里注意本地的文件路径为:http://localhost:8081/iosPages/b.html
HTML文件 /iosPages/b.html:
<h1>this is a html file</h1> <p>this is content hello </p>
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 ( <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;
相关推荐
dangai00 2020-07-18
xhpscdx 2020-05-31
chenxiangpeng 2020-04-30
ncuboy0wsq 2020-03-27
学习web前端 2020-03-23
APCDE 2020-03-04
歆萌 2020-03-03
csdnuuu 2020-01-04
水龙吟的备忘录 2019-11-18
icewizardry 2014-04-10
元元 2019-11-17
androidstudyroom 2019-11-08
czpaex 2011-09-11
OldSoldier 2011-08-18
wangdaiying 2011-05-26
qixiang0 2019-08-24