繁体   English   中英

从文件加载本地HTML

[英]Load local HTML from file

我是React Native的新手,我尝试在WebView中加载本地.html文件,但不幸的是,应用程序崩溃而没有任何控制台登录。

我的代码很简单:

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>

任何提示都将受到欢迎。 谢谢

我已经找到问题的答案,更新的return已发布在下面:

return (
    <WebView
      source={PolicyHTML} // object should be assigned directly to the WebView source property
      style={{width: width, height: height}}
   />
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM