【问题标题】:html file is not linking/executing properly with react-nativehtml 文件未与 react-native 正确链接/执行
【发布时间】:2018-08-27 08:28:14
【问题描述】:

我是开发 react-native 应用程序的新手,我需要在其中链接 html 文件。它在我的 android 模拟器上提供空白输出,甚至没有任何错误。我只想知道如何将 html 文件与 react native 链接。基本代码示例如下..

我已经浏览了下面的链接,但它在我的场景中不起作用.. (React Native) Load local HTML file into WebView

App.js

import React, { Component } from 'react';
import {
  View,
  WebView
} from 'react-native';

const DataHTML = require('./data.html');

export default class App extends Component<Props> {
  render() {
    return (
     <View>
        <WebView
            source={DataHTML} 
            style={{flex: 1}}
            />                
      </View>
    );
  }
}

数据.html

<html>
<head></head>
<body>
    <h1>Hello</h1>
</body>
</html>

【问题讨论】:

    标签: javascript react-native


    【解决方案1】:

    通常应该出现 WebView。尝试将 View 和 WebView 的 flex 设置为 1 或设置显式大小。

      <View style={{flex: 1}}>
        <WebView
           source={DataHTML}
           style={{flex: 1}}
        />
      </View>
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      相关资源
      最近更新 更多