Nuxt.js: ReferenceError : "window is not defined"

Created on 13 Nov 2017  路  3Comments  路  Source: nuxt/nuxt.js

code:
header.vue:

export default {
  data(){
    return {
      msgShadeHeight: window.innerHeight, // 娑堟伅閬僵锛岀偣鍑绘秷鎭梺杈圭敓鎴愮殑閬僵
      //...
    }
  },
}

could u please tell me whats the correct way to use "window" in data ?
thank u very much!

This question is available on Nuxt.js community (#c1857)
help-wanted

Most helpful comment

There is not DOM in server side, you should skip it

export default {
  data(){
    return {
      msgShadeHeight: null, // 娑堟伅閬僵锛岀偣鍑绘秷鎭梺杈圭敓鎴愮殑閬僵
      //...
    }
  },
  beforeMount() {
     this.msgShadeHeight = window.innerHeight
   }
}

All 3 comments

There is not DOM in server side, you should skip it

export default {
  data(){
    return {
      msgShadeHeight: null, // 娑堟伅閬僵锛岀偣鍑绘秷鎭梺杈圭敓鎴愮殑閬僵
      //...
    }
  },
  beforeMount() {
     this.msgShadeHeight = window.innerHeight
   }
}

i want to use 'echart.js' but when i render the page, ReferenceError : "window is not defined" , how to fixed it?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msudgh picture msudgh  路  3Comments

vadimsg picture vadimsg  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

gary149 picture gary149  路  3Comments

mikekidder picture mikekidder  路  3Comments