React-Native导入WebView报错:模块无该导出成员TS2305
解决React Native中WebView导入的TypeScript错误
问题原因
React Native 0.60及以上版本中,WebView组件已从核心的react-native模块移除,需使用独立第三方库react-native-webview。
解决步骤
安装
react-native-webview依赖
使用npm:npm install react-native-webview或者yarn:
yarn add react-native-webview针对iOS项目执行Pod同步(RN 0.60+支持自动链接,但iOS需同步Pod依赖)
cd ios && pod install && cd ..修改代码中的导入语句
将原有导入代码:import {WebView} from 'react-native';替换为:
import WebView from 'react-native-webview';
修改后的完整代码示例
import React, {Component} from 'react'; import WebView from 'react-native-webview'; class MyWeb extends Component { render() { return ( <WebView source={{ uri: 'https://github.com/facebook/react-native', }} style={{marginTop: 20}} /> ); } }
内容的提问来源于stack exchange,提问作者HelloCH
相关产品推荐
相关产品推荐

