我尝试在Webview第一次加载时使用react-native-webview传递一些变量数据。然而,它似乎不像我使用模板文字那样工作。
const arr = ["something"]
const injectedJS = `let webviewArr = ${arr}`
return (
<WebView
scalesPageToFit={false}
mixedContentMode="compatibility"
injectedJavaScript={injectedJS}
src={{ html: `some html here` }}
/>
)
字符串
为什么不管用?如果我只使用硬编码的数据,它工作得很好。但是当我需要从其他地方导入数据并将其植入我的Webview时,这种方法只会破坏应用程序。
2条答案
按热度按时间ecfsfe2w1#
我发现双重字符串化(我不知道还能怎么说)工作得很好。
字符串
或
型
让我知道是否有更好的解决方案。
wnvonmuf2#
就这么做:
字符串