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

时间:2020-05-28 18:27:31

标签: react-native react-native-webview

如何清除react-native-webview

localStorage

清除网络视图的本地存储的最佳方法是什么

1 个答案:

答案 0 :(得分:0)

我们可以使用clearLocalStorage = () => { this.setState({ isCookieClear: true }, () => { setTimeout(() => { this.setState({ isCookieClear: false }); }, 2000); }); }; 清除本地存储。我们可以称之为this.clearLocalStorage();清除localStorage

const {isCookieClear}=this.state;

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

return (
<WebView
 ref="webview"
 javaScriptEnabled={true}
 domStorageEnabled={true}
 injectedJavaScript={myInjectedJs}
 useWebKit={true}
 />
)
<div class='col-12 col-xl-6'>