(React Native) 将本地 HTML 文件加载到 WebView [英] (React Native) Load local HTML file into WebView

查看:36
本文介绍了(React Native) 将本地 HTML 文件加载到 WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 React Native 中将本地 .html 文件加载到 WebView 中:

I try to load the local .html file into WebView in React Native:

// 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 文件应作为字符串读取,而不是作为资源代表读取.

The .html file should be read as a string, not as a resource representative.

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

How can I load the .html file into WebView in React Native?

顺便问一下,require() 中的那些资源代表是什么类型的?是数字吗?

By the way, what is the type of those resource representatives from require()? Is it number?

推荐答案

试试看:

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

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

这篇关于(React Native) 将本地 HTML 文件加载到 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆