Home

Issue: 3096

How do I add a listener event on the server side?

[issue link]

I need to add a listening keyboard event to the page, but now I’m using nuxt to add the listener failure.

`
created(){
//注册全局变量

  if(process.browser){
    const _this = this;
    _this.hotelMarquee = this.hotel[this.language_code].length>18;
    document.onkeydown = function(e) {
      _this.changeLanguage(e.which)
    };
  }
},

}
`
The results of the operation are wrongly reported as follows:

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

This question is available on Nuxt.js community (#c2680)