我环顾了Ionic 4的新平台,似乎registerBackButtonAction
函数已从中删除。
还有其他方法可以处理Android硬件后退按钮吗?
答案 0 :(得分:10)
更新:此问题已在dfac9dc
中修复Related: how to integrate hardware back button into ionic4 navigation
这在GitHub,Ionic Forums和Twitter中被跟踪
在正式修复之前,您可以使用以下解决方法:
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月)
registerBackButtonAction
是just a wrapper的corresponding 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);
没错,它是解决方案的一部分:)