【问题标题】:How to handle android back button on webview in nativescript vue如何在nativescript vue中处理webview上的android后退按钮
【发布时间】:2020-02-17 13:05:21
【问题描述】:

所以在 nativescript-vue 中,我有一个 webview,用户可以浏览其中的页面。但是当他们按下物理后退按钮时,应用程序会退出,而不是返回到 webview 上的上一页。

<WebViewExt :src="webviewLink" builtInZoomControls="false" displayZoomControls="false" />

我们该如何处理?

【问题讨论】:

    标签: android webview back-button nativescript-vue


    【解决方案1】:

    自己解决了。

    首先,将其添加到脚本的顶部:

    const application = require("tns-core-modules/application");
    

    然后在您的 mounted 函数中检查后退按钮活动。

    if (application.android) {
                application.android.on(application.AndroidApplication.activityBackPressedEvent, function (args) {
                    console.log("Event: " + args.eventName + ", Activity: " + args.activity);
        Set args.cancel = true; // to cancel back navigation and do something custom.
                });
            }
    

    更多信息在这里:https://docs.nativescript.org/core-concepts/application-lifecycle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多