https://nuxtjs.org/docs/concepts/server-side-rendering#window-or-document-undefined

 

Server Side Rendering

Server-side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it in the browser.

nuxtjs.org

 

Nuxt.js에서 window 객체를 사용을 하려면 문제가 생긴다. 

 

window is undefined

window is undefined

 

 

원인의 오류는 Nuxt.js는 SSR (Server Side Rendering)이기 때문이다. 

 

처음에 nuxt를 실행하면 각종 설정과 lifecycle을 실행하게 되는데 이때, Server Side에는 window 객체가 없으므로 문제가 생기는 것이다. 

 

이런 오류를 종종 본다. html에서는 <client-only>를 통해 해결할 수 있다. 

 

데이터에서는 process.client 를 사용할 수 있다. client side rendering일 때, 실행시키라는 의미이다. 

 

 

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js Quill Editor  (0) 2022.03.04
Nuxt.js Auth (Naver)  (0) 2022.03.01
Nuxt.js Lottie 사용하기  (0) 2022.02.27
Eslint Babel정리  (0) 2022.02.27
Nuxt.js Buefy Pagination  (0) 2022.02.26

+ Recent posts