GithubHelp home page GithubHelp logo

Comments (2)

aarontraynor avatar aarontraynor commented on July 19, 2024 3

Hey! I had the same struggle when I was trying to figure it out so hopefully this will get you up and running!

plugins/idle-vue.js:

import Vue from 'vue';
import Vuex from 'vuex';
import IdleVue from 'idle-vue';

const store = new Vuex.Store({
    state: {
        isIdle: false,
    }
});
const eventsHub = new Vue();

Vue.use(IdleVue, {
    eventEmitter: eventsHub,
    store,
    idleTime: 60000
    startAtIdle: false
  });

nuxt.config.js

plugins: [
    { src: "@/plugins/idle-vue", ssr: false },
    ...
]

You can then access isAppIdle through a computed value in your component:

computed: {
    isIdle() {
        return this.$store._vm.isAppIdle;
    },
    ...
}

However, for most cases you should be able to make use of the onIdle() and onActive() hooks provided. If that works for you, you can simplify your idle-vue.js file like so:

import Vue from 'vue';
import IdleVue from 'idle-vue';

const eventsHub = new Vue();

Vue.use(IdleVue, {
    eventEmitter: eventsHub,
    idleTime: 60000
    startAtIdle: false
  });

then in the component you wish to use the idle timer in, you can use the hooks as follows:

async onIdle() {
    this.doSomethingWhenUserIsIdle();
}
async onActive() {
    this.doSomethingWhenUserIsNoLongerIdle();
}

Hope this helps! :)

from idle-vue.

lieunttuit avatar lieunttuit commented on July 19, 2024

@aarontraynor Thank you so much, May be i forgot init isIdle for Vuex. I'm using of the onIdle() and onActive() hooks provided. It work fine!

from idle-vue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.