项目作者: ECJ222

项目描述 :
Page visibility module for Nuxt.js
高级语言: JavaScript
项目地址: git://github.com/ECJ222/nuxt-page-visibility.git
创建时间: 2021-06-07T08:57:30Z
项目社区:https://github.com/ECJ222/nuxt-page-visibility

开源协议:

下载


🌫️ nuxt-page-visibility

npm version
npm downloads
License

A Nuxt.js module to detect page visibility

Table of Contents

Requirements

  • npm
  • NuxtJS
  • NodeJS

Install

  1. # npm
  2. $ npm install nuxt-page-visibility
  3. # yarn
  4. $ yarn add nuxt-page-visibility

Getting Started

Add 'nuxt-page-visibility' to the modules section of your nuxt.config.js file.

  1. {
  2. modules: ["nuxt-page-visibility"];
  3. }

Usage

  1. Inject the module in your nuxt.config.js file. See Getting Started.
  2. this.$visibility is now available in your components. Note that $visibility returns an object with two properties one is isVisible which we would use to check if a user is focused on a page or not, While the other isSupported is used to check if the browser supports the Page Visibility API.
  1. {
  2. ...
  3. watch: {
  4. $visibility: {
  5. handler (page) {
  6. if (page.isVisible) {
  7. // do something
  8. } else {
  9. // do something
  10. }
  11. },
  12. deep: true
  13. }
  14. }
  15. ...
  16. }

License

This project is licensed under MIT