javascript - 如何在 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,必须有另一种方法来做到这一点。引导我。
解决方案
推荐阅读
- windows - 从控制面板获取用户首选语言列表的正确方法是什么?
- flutter - AWS Amplify,初始化失败
- c# - 从服务中读取本地安全策略
- go - 为什么 Go Programming 将任何以零开头的数字视为八进制,我该如何防止这种情况发生?
- rust - 如何在赋值时解决“预期结构,找到类型参数”?
- flutter - 将对象转换为可编码对象失败:'_CompactLinkedHashSet 的实例
- >'
- entity-framework - EntityTypeConfiguration 中没有忽略属性?
- git - 如何对支持不同依赖版本的多个发布分支进行版本控制?
- reactjs - 无法匹配 Firebase 中的用户
- apache - 如何在 OpenShift Online Pro 中禁用路由的 tls 1.0 和 1.1