android - 如何在 Nativescript Vue WebView 中启用 LocalStorage?
问题描述
我的 Nativscript Vue 应用程序中有一个WebView
,但在 Android 上,嵌入式网站无法访问浏览器中的 localStorage。这个问题解释了如何为 Angular 做这件事。问题是不清楚应该从哪里获取 webview 实例。完整性问题:如何访问包含该android
属性的 WebView 实例以启用本地存储?
解决方案
这就是我最终解决它的方法。我需要访问通过属性中的事件处理程序传递的 WebView event.object
。组件上没有调用事件onWebViewLoaded
,因为这不是 Angular。相反,我们需要挂钩元素上的loadFinished
事件。WebView
<template>
<Page>
<WebView
src="https://www.example.com/"
@loaded="onLoaded"
/>
</Page>
</template>
<script>
export default {
methods: {
//when the webview finishes loading
onLoaded(event) {
//get the webview
const webView = event.object
//if there is android
if (webView.android) {
//enable dom storage in the webview on android
webView.android.getSettings().setDomStorageEnabled(true)
}
}
}
}
</script>
推荐阅读
- c++ - 使用 void_t 和受保护的嵌套类的基于 SFINAE 的检测
- java - DataExporter 无法在 Primefaces 中的 dataTable 上使用列过滤器
- c# - JSON 后返回后 MVC RedirectToAction 不起作用
- c++ - 使用 WinAPI 处理用户注销的问题
- ios - 使用 Objective-C 为图像和其他参数发布多部分/表单数据
- c++ - C++/Thrift:TThreadedServer::stop() 线程安全吗?
- java - Jackson - @JsonCreator 返回泛型
- android - Kotlin ViewModel 类中预期的属性 getter 或 setter
- python - 图 matplotlib
- r - 如何从 R 中的多个列表/向量制作重叠表?