A Nuxt.js module to detect page visibility
- npm
- NuxtJS
- NodeJS
# npm
$ npm install nuxt-page-visibility
# yarn
$ yarn add nuxt-page-visibility
Add 'nuxt-page-visibility'
to the modules
section of your nuxt.config.js
file.
{
modules: ["nuxt-page-visibility"];
}
- Inject the module in your
nuxt.config.js
file. See Getting Started. this.$visibility
is now available in your components. Note that$visibility
returns anobject
with two properties one isisVisible
which we would use to check if a user is focused on a page or not, While the otherisSupported
is used to check if the browser supports the Page Visibility API.
{
...
watch: {
$visibility: {
handler (page) {
if (page.isVisible) {
// do something
} else {
// do something
}
},
deep: true
}
}
...
}
This project is licensed under MIT