运行 Ionic Vue 关闭或应用程序在后台运行之前的操作

Run action before Ionic Vue closes or app runs in background

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

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

您可以订阅 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
        ...
      }
    })
  }
}