0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nuxt.js で window が使えない

Posted at

Nuxt.js で window を使ったところ、エラーが出てしまいます。


ReferenceError
window is not defined

これはサーバーサイドのレンダリングが原因でした。
公式サイトに書いてあります。

process.client 変数を使用する必要があるということで、公式サイトの例を参考にして下記のように書いて解決しました。

if (process.client) {
  // ここに window を使った処理を書く
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?