gpt4 book ai didi

webview - (React Native) 将本地 HTML 文件加载到 WebView 中

转载 作者:行者123 更新时间:2023-12-02 03:59:14 27 4
gpt4 key购买 nike

我尝试将本地 .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 文件应作为字符串读取,而不是作为资源代表读取。

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

<小时/>

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

最佳答案

尝试一下:

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

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

关于webview - (React Native) 将本地 HTML 文件加载到 WebView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42851296/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com