为了账号安全,请及时绑定邮箱和手机立即绑定

React Native 渲染 html 出现错误 => 打开 URL 时出错

React Native 渲染 html 出现错误 => 打开 URL 时出错

PIPIONE 2024-01-11 17:08:09
我使用 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 我希望它有帮助


查看完整回答
反对 回复 2024-01-11
  • 1 回答
  • 0 关注
  • 40 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信