Quasar 使用 Web 页面可见性 API,它可以让你知道网站/应用何时可见或处于焦点状态。
// quasar.config file
return {
framework: {
plugins: [
'AppVisibility'
]
}
}
content_paste
用法
import { AppVisibility } from 'quasar'
AppVisibility.appVisible // Boolean
// inside of a Vue file
import { useQuasar } from 'quasar'
setup () {
const $q = useQuasar()
// now use $q.appVisible (Boolean)
}
content_paste
监控状态变化
<template>...</template>
<script>
import { useQuasar } from 'quasar'
import { watch } from 'vue'
export default {
setup () {
const $q = useQuasar()
watch(() => $q.appVisible, val => {
console.log(val ? 'App became visible' : 'App went in the background')
})
}
}
</script>
content_paste