reference error: "window is not defined" when using in Nuxt.js
Closed this issue · 2 comments
phivk commented
I'm trying to use this plugin in Nuxt.js.
So far I did (based on the example code):
npm install --save idle-vue
- created
/plugins/idle-vue.js
with the following content:
import Vue from 'vue'
import IdleVue from 'idle-vue'
const eventsHub = new Vue()
Vue.use(IdleVue, {
eventEmitter: eventsHub,
idleTime: 10000
})
- imported the plugin in
/nuxt.config.js
:
plugins: [
{ src: '@/plugins/idle-vue.js'}
],
- added hooks to my Nuxt page Vue instance:
onIdle() {
console.log('ZZZ');
},
onActive() {
console.log('Hello');
},
This causes Nuxt to report reference error: "window is not defined"
voltane commented
According to documentation, for Nuxt.js <2.4 change plugins in nuxt.config.js as follow:
plugins: [
{ src: '@/plugins/idle-vue.js', ssr: false}
],
For Nuxt 2.4< use this:
plugins: [
{ src: '@/plugins/idle-vue.js', mode: 'client'}
],
phivk commented
thanks for pointing me in the right direction, this works 👍