我try 将本地.html文件加载到React Native中的WebView:

// load local .html file
const PolicyHTML = require('./Policy.html');

// PolicyHTML is just a number of `1`
console.log('PolicyHTML:', PolicyHTML);

// will cause an error: JSON value '1' of type NSNumber cannot be converted to NSString
<WebView html={PolicyHTML} />

.html文件应该作为字符串读取,而不是作为资源代表读取.

如何在React Native中将.html文件加载到WebView中?


顺便问一下,require()人中的资源代表是什么类型的?是number吗?

推荐答案

试试看:

const PolicyHTML = require('./Policy.html');

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

React-native相关问答推荐

如何在renderItem中显示每个项目的索引号,保持分页的前一个下一个按钮

复制__自持props

如何在Reaction本地日历中 Select 年份?

React Native - 何时调用componentWillUnmount?

Eslint 错误,configuration for rule "import/no-cycle" is invalid

最近 react-native 版本中的Unable to resolve moduledebuggerWorker 错误

TabNavigator 中的 React Navigation 传递props

如何使用 AsyncStorage React Native 缓存 API 数据

图像背景ResizeMode调整大小模式

为了回调 URL 的目的,在 Expo 中运行的 React Native 元素的 info.plist 在哪里?

React Native:双击退出应用程序

React Native - 如何判断 UI/元素?

为什么 Android Studio 强制使用 Android 支持库中的 Androidx?

React Native:自定义字体在 Android 和 iOS 上呈现不同

如何在 Text 中围绕 Text 包裹 TouchableOpacity?

Unexpected token on "export default const"

React.createClass vs. ES6 箭头函数

react-native:webview 高度

React Context:TypeError:render is not a function

react-native iOS 应用在部署后不显示静态/本地资源