如何在nativescript vue中处理webview上的android后退按钮

问题描述 投票:0回答:1

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

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

我们该如何处理?

android webview back-button nativescript-vue
1个回答
0
投票

自己解决。

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

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

然后在您的已安装功能中,检查后退按钮活动。

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

© www.soinside.com 2019 - 2024. All rights reserved.