Comments (2)
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.
@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)
- Error: 'idleVue_onIdle' of undefined HOT 2
- How to pause or stop idle and start again HOT 2
- isAppIdle returns true the moment the app loads/Route refreshes HOT 2
- what is the actual timer in this? I don't understand HOT 2
- This project still maintained? HOT 2
- Difficulty dynamically setting idleTime HOT 3
- reference error: "window is not defined" when using in Nuxt.js HOT 2
- onActive() Hook works only on first tab
- Can the idleTime be set after initialisation? HOT 3
- isIdle for All Tabs HOT 5
- idle-vue seems to prevent reload nuxt app
- Vue 3 support HOT 9
- Tracking idle timeout when the user navigate away to a different domain and return back
- Inquiry about tracking the idle users HOT 1
- Not working when deployed to server. Anyone has this issue? HOT 4
- Update the value of the isIdle in vuex by calling a mutation.
- Does idle-vue support TypeScript?
- Is idle vue supports foe multiple tabs ? HOT 1
- vue3 compatible? Vue.extend is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idle-vue.