如何清除 react-native-webview 的本地存储?

how to clear local storage of react-native-webview?

如何清除 react-native-webview

localStorage

清除 webview

localstorage 的最佳方法是什么

我们可以使用injectedJavaScript清除本地存储。我们可以调用 this.clearLocalStorage();清除 localStorage

clearLocalStorage = () => {
    this.setState({ isCookieClear: true }, () => {
      setTimeout(() => {
        this.setState({ isCookieClear: false });
      }, 2000);
    });
  };
const {isCookieClear}=this.state;

let myInjectedJs = `(function(){
  ${isCookieClear?`window.localStorage.clear(); `:''}
})();`

return (
<WebView
 ref="webview"
 javaScriptEnabled={true}
 domStorageEnabled={true}
 injectedJavaScript={myInjectedJs}
 useWebKit={true}
 />
)