Issue with displaying content using v-show in a Nuxt.js menu

Struggling to create a mobile menu with Vue instance error

The Nuxt Menu Component :

<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.open = false
            }
        },
    }
    
</script>

Error Snapshot

https://i.stack.imgur.com/IcfTP.png

Answer №1

To ensure that each instance maintains a unique copy of its data, the data option should be set to a function that returns an object.

To update your code snippet, make the following change:

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

For more detailed information, refer to data Must Be a Function in the Vue documentation.


On a side note, as pointed out by Lawrence, there is a minor typo in the menu open function (ouvert should be corrected to open). If you wish to toggle the menu, you can use the following method:

methods: {
  menu() { // Toggle menu open state
    this.open = !this.open;
  },
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Vue-chartjs and axios to create a dynamic stacked bar chart

Within my template, I include: <BarChart v-if="loaded" :data1="data1" :data2="data2" :chart-labels="labels" /> For the script section, I have: this.loaded = false axios.get(`url`).then((response) => ...

Exploring the Power of Laravel 5.5 and Vue.js 2.x for Efficient API Calls

Currently, I am working on a Laravel 5.5 project locally that incorporates Vue.js 2.5.9 with XAMP Server. One of the tasks I have is to load certain information onto the DOM and then refresh it upon clicking the "Refresh" button. However, there seems to ...

Storing a screen value with javascript made simple

I need to incorporate memory functions into my calculator, specifically MS (Memory Store), MR (Memory Restore), and MC (Memory Clear). For Memory Store, the screen value of the calculation needs to be saved, so if it's 90 + 7 = 97, that result should ...

Prevent animation when expanding the menu in Vue using CSS

The animation only works when collapsing the menu, not when expanding it. I tried adding CSS for setting a max-height, but the animation only functions when collapsing the menu. <template> <div> <p> <button @click="is ...

Troubleshooting ASP.NET Content Page Error: jQuery Object Expected

Currently working on designing a personal ASP.NET Web page, I have encountered an issue with making a sticky div using jQuery. Despite all my other jQuery functions functioning properly, the sticky div seems to be causing trouble. stickydiv.js $(document ...

Move information from one webpage to a different page

After developing a site using NextJs, I successfully integrated Discord login functionality and was able to retrieve the user's guilds in the oauth file. Now, I am looking to send this list of guilds (in JSON format) to my dashboard page. In the oau ...

Is there a way for me to dynamically decide whether to use the append or prepend function?

Utilizing jQuery to retrieve data from the controller and populate a calendar represented by a table with days in columns. Implementing functionality for navigating between previous week / next week, as well as previous day / next day. The four scenarios s ...

Understanding how Vue CLI v3 determines which JavaScript files should be separated into different chunks

Struggling to grasp the new CLI and configuration adjustments. The official documentation lacks details on incorporating CSS as an entry point instead of directly importing it into a component or main.js. Noticing that some JS files are being split into s ...

What is the best way to navigate through multi-dimensional arrays of objects in JavaScript?

I am trying to access JavaScript objects that are stored in a multi-dimensional array, which is being exported by a WordPress plug-in. Unfortunately, I cannot make changes to the code to use a single array. There are two arrays called "employees". Is this ...

Using regular expressions to extract the value of a specific key from a JavaScript object

After scraping a webpage with BeautifulSoup and requests, I came across this snippet of code within the HTML content: $create(Web.Scheduler, { "model": '{"apt":[0]}', "timeZone": "UTC", "_uniqueI ...

Unpredictable jQuery Ajax setTimeout

I have a script that retrieves data from ajax.php and displays it in a div. The intention is for the information to be shown for a period of 3 seconds before hiding the #ajax-content and displaying #welcome-content. Most of the time it works as intended, ...

Synchronous AJAX requests do not function properly in IE and Firefox, but they do work in Chrome and Safari

Attempting to measure download speed using an AJAX call. Below is the code snippet: var start = new Date(); $.ajax ({ url: 'https://www.example.com/perftest/dummyFile1024', cache: false, success : function() { var total = ( ...

How to eliminate a particular item within a string only in rows that include a different specific item using JavaScript

Is my question clear? Here's an example to illustrate: let string = "Test text ab/c test Test t/est ### Test/ Test t/test Test test" I want to remove / only from the line that includes ###, like so: Test text ab/c test Test t/est ### Test T ...

JavaScript for_each loop

Is there a way to access the field index of a JSON-Array when looping through it? I am aware that there is no foreach-loop like in PHP. This is an example of my json: { 'username': 'Karl', 'email': '<a href=" ...

Troubleshooting React: Child Component Fails to Render

Currently, I am enrolled in a React course and deep diving into the lifecycle methods of React. Through implementing componentDidMount, I have successfully made API calls and set the state accordingly. However, I am facing an issue with displaying images ...

What is the best way to incorporate a description box for each city on the svg map that appears when you hover your mouse over it?

I am looking to display detailed descriptions for each city in the same consistent location on my map. With multiple pieces of information to include for each city, I want to ensure that the description box is positioned at the bottom of the map. Can any ...

Using the Flow type checker with React library results in complications

I'm fairly new to JavaScript and React, so I appreciate your patience! I've recently started a project using create-react-app with React version 16.12.0. I installed a library that seems to be utilizing Flow. When attempting to use this library ...

Automatically close the multiselect dropdown when the user interacts outside of it (varied scenario)

For those interested, check out this jsfiddle link: http://jsfiddle.net/jaredwilli/vUSPu/ This specific code snippet focuses on creating a multi-select dropdown feature. When a user chooses options from the dropdown and then clicks outside of the menu are ...

I'm curious if there is a method in React Native to dynamically alter the color of a button depending on a boolean value retrieved from a database source

Hey there, I'm completely new to React-Native and just started playing around with it. I encountered an issue where I needed a button to change its color dynamically between "green" and "red" based on a boolean value from a database. Currently, I am ...

Ways to disperse items within another item

I have an inner object nested inside another object, and I am looking to extract the values from the inner object for easier access using its id. My Object Resolver [ { _id: { _id: '123456789', totaloutcome: 'DONE' }, count: 4 }, { ...