Exploring a Vue side menu drawer concept within Nuxt - what's the next move?

I've managed to emit the toggle event in the console, as shown below, but I'm unsure of what to do next. How can I make my event display a division? Currently, I am only able to show it using v-if="toggle=true", however, it doesn't disappear when I create that div.

<template>
  <div
    class="drawer-toggle"
    role="button"
    @click="$emit('toggle')">
    <div class="bar"></div>
    <div class="bar"></div>
    <div class="bar"></div>
  </div>
</template>

<style scoped>
.drawer-toggle {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 50%;
  width: 35px;
  cursor: pointer;
}

@media (min-width: 768px) {
  .drawer-toggle {
    display: none;
  }
}

.drawer-toggle .bar {
  width: 90%;
  height: 2px;
  background-color: white;
}
</style>

Below is a screenshot of the console:

https://i.sstatic.net/Lg7Jk.png

Answer №1

When dealing with parent-child communication, the parent must actively listen for events emitted by the child component. In the context of <TheHeader>:

<TheSideNavToggle @toggle="doSomething">
methods: {
   doSomething() {
      this.showFlag = !this.showFlag
   }
}

The @toggle attribute is set up to listen for an event named "toggle" and trigger the doSomething method when that event is emitted. If a value were to be emitted along with the event, it would be accessible as an argument in the method.

To toggle the visibility of the desired item:

<div v-if="showFlag">  <!-- or v-show -->

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

Data in Vue.js is currently not defined

Hi, I just started learning Vue.js. I would greatly appreciate any advice. I am encountering an issue where I am getting comments: undefined and as a result, the comments are not displaying. However, the xhr status is normal with 200. Thank you very mu ...

Transmit the image produced by the frontend JavaScript

I recently acquired a third-party library that has the capability to generate screenshots. https://i.sstatic.net/dxEcb.png I am eager to store these screenshots on my server, and I am currently utilizing Axios. I believe it involves working with blobs, a ...

Displaying or concealing an input field in vue.js depending on the selection of a radio button

I am currently working on customizing a pre-built form in Vue.js, where certain inputs are displayed or hidden based on the selection of two radio buttons: <b-form-group label-class="ssrv-form-control"> <div class="ssrv-5"& ...

Determining the necessary data to send via ajax for a particular issue

Currently, I am learning JavaScript and have encountered another challenge along the way. I am looking for assistance in understanding the concept, whether it is a solution in jQuery or Angular. I have two types of tasks in my HTML - audio or graphic. The ...

The React DevTools display components with the message "Currently Loading."

I am currently facing an issue with debugging some props used in my React application. When I try to inspect certain components, they display as "Loading..." instead of showing the normal props list: https://i.sstatic.net/RtTJ9.png Despite this, I can con ...

Limit the use of Javascript specifically within a section of HTML that includes a rich-text editor

Currently, I am working on a web application that has a historic background. This application uses the summernote editor, a rich-text editor that allows users to save formatted notes to the server. Along with this, there are numerous instances of inline Ja ...

Error in Rails app when incorporating Stripe API with Javascript involved

Incorporating Stripe into my rails app using the Koudoku gem has been challenging. When attempting to load the page for capturing user credit card information, I encounter an error in my JS console: Uncaught ReferenceError: $ is not defined (anonymous fun ...

Tips for choosing an <li> element with JavaScript

<style> .sys_spec_text{} .sys_spec_text li{ float:left; height:28px; position:relative; margin:2px 6px 2px 0; outline:none;} .sys_spec_text li a{ color: #db0401; height:24px; padding:1px 6px; border:1px solid #ccc; background:#fff; dis ...

What is the best approach for filtering a nested array in this scenario?

Here is the response I am getting: let m = [ { name: 'Summary', subListExpanded: false, subList: [ ] }, { name: 'Upload', subListExpanded: false, subList: [ ...

The note-taking app's JavaScript code does not currently have the capability to store notes in local storage

const noteContainer = document.querySelector(".note-container"); const createBtn = document.querySelector(".btn"); let notes = document.querySelectorAll(".input-box"); function showNotes() { noteContainer.innerHTML = localS ...

What could be causing jQuery to fail to detect changes in the HTML code?

Whenever I trigger an Ajax request and update an attribute value, the DOM reflects the changes as expected. However, upon clicking the button again, the console displays the old attribute value. It seems like the markup isn't recognizing the change an ...

Mongo: executing queries with both .find() and .update() methods sequentially

I am looking to: Retrieve specific items from collection X; Retrieve other items from X; Make the items from step #1 have the same value as the items from step #2 Make the items from step #2 have the same value as the items from step #1 Essentially, ...

Encountering the error "bash: typeorm: command not found" post installation of typeorm globally on a linux system

Operating System: Running macOS Sierra v 10.12.6 This is my first experience using Typescript and typeorm as I attempt to develop an application. I have tried both of the following commands to install typeorm: npm i -g typeorm & sudo npm i -g type ...

How can I retrieve an attribute from another model in Ember using the current handlebar in the HTML file?

I'm attempting to achieve the following: {{#if model.user.isAdmin}} <div> My name is {{model.user.name}} </div> {{/if}} within a handlebar that is being used in a controller unrelated to users: <script type="text/x-handlebars" data- ...

Don't display the title if there is no query made in Angular

At the moment, my current setup looks like this: <title ng-bind-template="FuturePhones: {{query}}">FuturePhones</title> However, this results in the title displaying as follows when the page loads: FuturePhones: When I query my controlle ...

The DataTable is becoming distorted following the Axios get request update

I am encountering an issue with my data table while populating the tbody using Axios get call. The pagination does not work properly and sometimes the displayed row count is incorrect. For example, even if the new data only consists of 10 rows, it might sh ...

Ways to eliminate the constant presence of the 'loading' cursor on screen

Currently, I have an interval in place that triggers an AJAX call to check for updates on the page (similar to how Facebook or StackExchange handle notifications). However, this call is causing two issues - it changes the cursor to a 'progress' o ...

Tips for initiating and terminating the evaluation of a condition at regular intervals using JavaScript

I'm currently working on a JavaScript application where I need to achieve the following: Periodically check every 5 seconds to see if there is an element with the 'video' tag on the page. Once an element with the 'video' tag ...

How can I fix the issue with the Google Maps info window button not transferring the value in JavaScript

I have integrated Google Maps to display details. When I click on the marker icon, an info window opens up. I have included some values in the info window, but when I click on it, the value is not being passed. How can I resolve this issue? When I click ...

Innovative User Handle Generation using Firebase in a React/Javascript Environment

My goal is to create new users using Firebase authentication and store their information in Firestore. Everything was going smoothly until I encountered the challenge of generating unique usernames. What would be the most effective approach to tackle this ...