首页 > 解决方案 > html 文件未与 react-native 正确链接/执行

问题描述

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

我已经浏览了下面的链接,但它在我的场景中不起作用.. (React Native)将本地 HTML 文件加载到 WebView

应用程序.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>

标签: javascriptreact-native

解决方案


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

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

希望这可以帮助 !


推荐阅读