ReferenceError:未定义窗口Nuxtjs

时间:2020-06-18 06:52:47

标签: vue.js nuxt.js

global.js

import Vue from 'vue'

// javascript import for when you're importing the css directly in your javascript
import "vue-navigation-bar/dist/vue-navigation-bar.css";

// import the library
import VueNavigationBar from "vue-navigation-bar";

Vue.component("vue-navigation-bar", VueNavigationBar);

nuxt.config.js

plugins: [
    { src: '~/plugins/global.js', ssr: false }
  ],

错误

window is not defined

我已经尝试了nuxtjs文档中的所有可能解决方案,但仍收到相同的错误。 谢谢!

1 个答案:

答案 0 :(得分:1)

解决方案是将其包装在<client-only>

​<​template​>
   <client-only>
      <​vue-navigation-bar​ :​options​=​"​navbarOptions​" /​>
   </client-only>​​
<​/​template​>