我嘗試加載 HTML 文件取決于其他 .js 文件。所以我寫了這樣的代碼,但是在 webview 中得到了純文本。render = () => { let source; if (__DEV__) { source = require('./vendor/Editor/index.html'); } else { source = Platform.OS === 'ios' ? require('./vendor/Editor/index.html') : {uri: 'file:///android_asset/vendor/Editor/index.html'}; } return ( <WebView startInLoadingState source={source} onMessage={this.handleMessage} automaticallyAdjustContentInsets={false} style={[ AppStyles.container, styles.container, {height: this.state.visibleHeight}, ]} /> ); };我像這樣簡化代碼,但它也不起作用。 render = () => { setTimeout(() => { this.webview.injectJavaScript( 'window.ReactNativeWebView.postMessage(document.body.innerHTML)', ); }, 3000); return ( <WebView source={require('./vendor/GrEditor/index.html')} onMessage={e => console.log('e: ', e)} /> ); };對不起語法不好。
react-native-webview 加載本地 HTML 文件但得到純文本
FFIVE
2022-06-16 10:50:22
