平台4的Ionic 4替代品

时间:2018-08-07 13:37:25

标签: ionic-framework ionic4

我环顾了Ionic 4的新平台,似乎registerBackButtonAction函数已从中删除。

还有其他方法可以处理Android硬件后退按钮吗?

3 个答案:

答案 0 :(得分:10)

更新:此问题已在dfac9dc

中修复

Related: how to integrate hardware back button into ionic4 navigation


这在GitHubIonic ForumsTwitter中被跟踪
在正式修复之前,您可以使用以下解决方法:

this.platform.backButton.subscribe(() => {
  // code that is executed when the user pressed the back button
})

// To prevent interference with ionic's own backbutton handling
// you can subscribe with a low priority instead
this.platform.backButton.subscribeWithPriority(0, () => {
  // code that is executed when the user pressed the back button
  // and ionic doesn't already know what to do (close modals etc...)
})

请注意,您需要保存subscribe(...)的结果 如果您想再次取消订阅。


旧答案:(截止至2018年4月)

registerBackButtonActionjust a wrappercorresponding Cordova call

因此,您可以将旧电话打到registerBackButtonAction

this.platform.registerBackButtonAction(() => { 
  // code that is executed when the user pressed the back button
});

并替换为:

this.platform.ready().then(() => {
  document.addEventListener("backbutton", () => { 
    // code that is executed when the user pressed the back button
  });
});

答案 1 :(得分:0)

我尝试过

<form @submit.prevent="editMode ? queryMode ? updateParticipant() : anotherMethod() : addParticipant()">

有效!

ionic git commit https://github.com/ionic-team/ionic/commit/978cc39009a9a0fb065540ce17e10c685b6c101a

答案 2 :(得分:0)

对于@ ionic / vue,您可以将其(或类似的东西)放在main.js中

import { Plugins } from '@capacitor/core'

Plugins.App.addListener('backButton', function() {
  console.log(111);
  window.history.back();
});

不,不,console.log(111);没错,它是解决方案的一部分:)