我是React Native的新手,我尝试在WebView中加载本地.html文件,但不幸的是,app没有任何登录控制台崩溃。
我的代码非常简单:
import React, { Component } from 'react';
import { AppRegistry, View, Text, Dimensions, WebView} from 'react-native';
class HTMLLoader extends Component {
render() {
const PolicyHTML = require('./text.html');
var {height, width} = Dimensions.get('window');
return (
<WebView
source={{html: PolicyHTML}}
style={{width: width, height: height}}
/>
);
}
}
export default class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
render() {
return (
<HTMLLoader/>
);
}
}
// skip these lines if using Create React Native App
AppRegistry.registerComponent(
'AwesomeProject',
() => IScrolledDownAndWhatHappenedNextShockedMe);
这是.html文件的内容:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
任何提示都会受到欢迎。感谢
答案 0 :(得分:0)
我找到了我的问题的答案,更新return
已在下面发布:
return (
<WebView
source={PolicyHTML} // object should be assigned directly to the WebView source property
style={{width: width, height: height}}
/>
);