简体   繁体   English

从文件加载本地HTML

[英]Load local HTML from file

I'm new in React Native and I try to load local .html file in WebView but unfortunately app crash without any log in console. 我是React Native的新手,我尝试在WebView中加载本地.html文件,但不幸的是,应用程序崩溃而没有任何控制台登录。

My code is very simple: 我的代码很简单:

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);

this is content of .html file: 这是.html文件的内容:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

any hint will be welcomed. 任何提示都将受到欢迎。 Thanks 谢谢

I have found answer for my question, updated return has been posted below: 我已经找到问题的答案,更新的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