react-native實現webapp

首先 webview已經從 react-native 移到單獨模塊 react-native-webview;

使用:

  1. 安裝 yarn add react-native-webview;
  2. 運行 react-native link react-native-webview(native0.6以後會自動link 不知道可不可以 )

如果報錯:

 

 
> Invariant Violation: requireNativeComponent: "RNCWKWebView" was not found in the UIManager.
>
  1. cd ios
  2. 運行 pod install
  3. 重新運行 react-native run-ios

在App.js代碼裏寫入

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';

// ...
export default class MyWebComponent extends Component {
  render() {
    return <WebView source={{ uri: 'https://www.baidu.com' }} />;
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章