我使用 RN、EXPO 和“react-native-render-html”庫來渲染 HTML 源。我想我得到了完美的原始 html,但是當我將它傳遞給像這樣的 HTML 標簽時<HTML html={this.state.html}我遇到這樣的錯誤打開 URL 時出錯:,[錯誤:無法打開 URL:file:///Users/wook/Library/Developer/CoreSimulator/Devices/ 1C8EB2FA-E386-4A53-B136-564DD66A9F86/data/Containers/Bundle/Application/7B6CBBAD- 1F30-48BD-86BB-E536E572854D/Exponent-2.15.3.tar.app/hiddenForm.jsp]我實際上在 stackoverflow 上的類似問題中做了很多事情,但我無法調試它有人可以幫助我嗎?下面是我的代碼import React from 'react';import { StyleSheet, Text, View, Button, TextInput, ScrollView, Dimensions } from 'react-native';import { createAppContainer, ThemeColors } from "react-navigation";import { createStackNavigator } from 'react-navigation-stack';import axios from "axios";import HTML from 'react-native-render-html';class Educlass extends React.Component { state = { 'html':'' } componentDidMount() { const { navigation } = this.props; const edu_html = navigation.getParam('html'); var myPromise = Promise.resolve(edu_html); myPromise.then((value) => { this.setState({'html': value} )}) } render() { return ( <ScrollView style={styles.container}> <HTML html={this.state.html} imagesMaxWidth={Dimensions.get('window').width} /> {/* <Text> {this.state.html} </Text> */} <Text>ad</Text> </ScrollView> ) }}const styles = StyleSheet.create({ container: { flex: 1 }})export default Educlass;我認為我的代碼中有很多問題,因為我是 RN 新手,但感謝解決我的問題(渲染 html)
1 回答

繁花不似錦
TA貢獻1851條經驗 獲得超4個贊
如果您想從外部 uri 渲染,請使用 WebView 而不是 html 渲染器
npm install --save react-native-webview
import { WebView } from 'react-native-webview';
<WebView source={{html: '<p>Here I am</p>'}} />
<WebView
source={{ uri: 'https://emir.drh' }}
/>
第一個用于處理內部 html,第二個用于 uri 我希望它有幫助
- 1 回答
- 0 關注
- 182 瀏覽
添加回答
舉報
0/150
提交
取消