0

如果应用程序关闭或应用程序是否发送到后台,我如何在 Ionic Vue 中检测?

this.platformplatform不可用或不起作用?!

4

1 回答 1

1

您可以订阅该appStateChange事件,如下所述:https ://capacitorjs.com/docs/apis/app

例子:

import { App } from '@capacitor/app'

export default {
  created () {
    App.addListener('appStateChange', state => {
      if (!state.isActive) { // if isActive is true, App got sent to foreground, if it is false, it got sent to the background
        ...
      }
    })
  }
}
于 2021-09-06T14:21:36.297 回答