当前位置: 首页 > news >正文

如何在移动端app里嵌套web页面之react-native-webview


前言

快速上手使用react-native-webview


官方指南,可查看详细使用教程

react-native-webview介绍

React Native WebView是 React Native 的社区维护的 WebView 组件。它旨在替代内置的 WebView(已从核心中移除)。

简单来说,就是可以实现将web页面嵌套在app里面,实现混合开发。

在expo中使用

安装

  // 官方推荐npm install --save react-native-webview// 对于pnpmnpm install --save react-native-webview

使用

import React, { Component } from 'react';
import { WebView } from 'react-native-webview';class MyWeb extends Component {render() {return (<WebViewsource={{ uri: 'https://infinite.red' }}style={{ marginTop: 20 }}/>);}
}

问题

如果使用npm或pnpm安装,可能报以下错误

报错

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes

解决

版本不匹配问题,可以使用expo直接安装

expo install react-native-webview

http://www.mrgr.cn/news/19745.html

相关文章:

  • 1.第二阶段x86游戏实战2-前言
  • 前端常用的几种设计模式--观察者模式、单例模式等
  • 【openwrt-21.02】T750 openwrt MT7916 WPS PBC功能实现
  • FFmpeg源码:get_audio_frame_duration、av_get_audio_frame_duration2函数分析
  • 云计算之网络
  • 【JS笔试题】模拟一个微任务
  • Spring 状态机
  • Serverless 应用引擎 SAE 助力袋拉拉研发提效 70%
  • 深度学习|模型推理:端到端任务处理
  • 前端入门了解
  • Pencils Protocol生态新进展,即将上线 Vault 产品
  • 23合并 K 个升序链表
  • 【python】Python如何通过线程池来提高程序的执行效率
  • Python中的self有什么作用
  • Java重修笔记 第四十六天 Map 接口、HashMap 类
  • 硬件工程师笔试面试知识器件篇——三极管
  • 2024年百度嵌入式面试题及参考答案(7万字长文)
  • C++中STL容器
  • 【YOLOv8系列】YOLOv8的GUI界面设计;在电脑本地实现YOLOv8的可视化交互界面设计(对摄像头的实时画面进行分类)
  • Ajax是什么?如何在HTML5中使用Ajax?