Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuxt.js document is not defined, problem with pugin

I added plugin: vue-burger-menu to my nuxt.js project. And i have an error: "document is not defined". I know, that this plugin is available only for client-side. So I found in vue documentation enter link description here what I have to do to fix it. It works only for first refresh. Then I have again document is not defined.

nuxt.config.js:

  build: {
vendor: ['vue-burger-menu'],
 }

 plugins: [
{ src: '~/plugins/vue-burger-menu.js', ssr: false }
],

Add a file to my plugins folder called "vue-burger-menu.js":

 import Vue from 'vue';
 import VueBurgerMenu from 'vue-burger-menu';

   if (process.browser) {

      Vue.use(VueBurgerMenu);

   }

nav template

 <template lang="pug">
   Slide(right)
        nav.menu_vertical
 </template>

 <script>
 import { Slide } from 'vue-burger-menu'
 export default {
 name: 'Nav',
 components: {
   Slide
 },
}

enter image description here

like image 358
anna Avatar asked Feb 25 '26 03:02

anna


1 Answers

Replace deprecated process.browser with process.client

if (process.client) {
   Vue.use(VueBurgerMenu);
}
like image 75
GrigorAtaryan Avatar answered Feb 27 '26 18:02

GrigorAtaryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!