Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Problem of instance v-show - Nuxt js menu

I am trying to do a simple menu for mobile, but I didn't solve a problem of instance of vue

My component nuxt Menu :

<template>
    <header id="menu" class="menu-g">
        <Nuxt-link to="/"><img src="~assets/logo.svg" alt="Logo de Lucas"/></Nuxt-link>
        <div v-show="open">
          <Nuxt-link to="/projets">Projets</Nuxt-link>
          <Nuxt-link to="/articles">Articles</Nuxt-link>
          <Nuxt-link to="/a-propos">À propos</Nuxt-link>
          <Nuxt-link to="#mecrire">M'écrire</Nuxt-link>
        </div>
        <div @click="menu()">Menu</div>
    </header>
</template>

<script>
    export default {
        data: {
            open: true,
        },
        methods: {
            menu: function() {
                this.ouvert = false
            }
        },
    }
    
</script>

My error

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In order for each instance to maintain an independent copy of it's data, the data option must be a function that returns an object.

So in your code snippet, just update to:

export default {    
  data: () => ({
    open: true,   
  }),
}

For more info, see data Must Be a Function in the Vue docs.


Side-note, as mentioned by Lawrence, you've got a small typo in the menu open function (ouvert --> open). If you want to toggle the menu, you can do something like:

methods: {
  menu() { // Toggle menu open state
    this.open = !this.open;
  },
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!