首页 > 解决方案 > 如何在 react-native 中将 Node JS 变量传递到 HTML 文件中?

问题描述

我目前正在做一个项目,我必须将 html 渲染成react-native-webview. 这部分工作正常。但是 HTML 是静态内容,我想在其中插入变量,以便 html 将具有动态数据。我想出的一个想法是将 Html 转换为字符串并添加如下所示的变量。

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

class MyInlineWeb extends Component {
  render() {
    let variable = "hello"
    return (
      <WebView
        originWhitelist={['*']}
        source={{ html: '<h1>'+variable+'</h1>' }}
      />
    );
  }
}

上面的解决方案是有效的,但是对于较大的 html,必须有另一种方法来做到这一点。引导我。

标签: javascripthtmlreactjsreact-native

解决方案


推荐阅读