【问题标题】:Load local HTML from file从文件加载本地 HTML
【发布时间】:2017-12-27 14:07:04
【问题描述】:

我是 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>

欢迎任何提示。谢谢

【问题讨论】:

    标签: javascript html react-native webview jsx


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 1970-01-01
      • 2022-06-25
      • 1970-01-01
      相关资源
      最近更新 更多