Learn how to show a `<div>` based on the values in a dynamic array using Vue.js

I am looking to toggle the visibility of a new div when any of the user links is clicked:

<ul id="pm-tabs"> 
  <li v-for="user in unreadMsgsList">       
     <a @click="openPMbox(user)"> ${user}</a>
  </li>
</ul>

The method I'm using is:

    openPMbox: function(user) {              
         this.isPmBoxOpenList[user] = !this.isPmBoxOpenList[user];
    }, 

The user data is stored in isPmBoxOpenList: [] and it has been confirmed that it is populated correctly.

The window that should show/hide looks like this and is separate from the above v-for loop:

<div class="pmbox" v-bind:disabled=="isPmBoxOpenList" >Some Text </div>

However, I am encountering an error in the template. I am unsure how to properly define pmbox, so any guidance on this would be appreciated.

P.S. It is worth noting that user is not defined in data. It is simply an object within the isPmBoxOpenList array.

Answer №1

To toggle the display of an element, you can utilize the v-if directive in this manner:

<div class="popup-message-box" v-if="isMessageBoxOpenList[user]" >Some Content </div>

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

How to use jQuery to retrieve the style of an element based on a specific data attribute

I've been using bxSlider and I decided to create a unique custom pager using the pagerCustom option. My goal was to make the pager resemble a thumbnail pager, so I attempted to copy the style of each slide and attach it to the corresponding pager. For ...

What is the reason why the beforeDestroy method is not invoked during a refresh, but the created method is triggered

I'm attempting to trigger a page refresh in vue.js. When doing so, I notice that the created hook is being called. Why isn't the destroyed hook triggered instead? If the created hook is being called, it suggests that the component should have be ...

Array automatically updates its values

.... import * as XLSX from 'xlsx'; ... I am currently parsing a .xlsx file in an Ionic 4 application. showData() { let fileReader = new FileReader(); fileReader.onloadend = (e) => { this.arrayBuffer = fileReader.result; let data ...

What is the technique for toggling a slide on a pseudo element?

Take a look at this jsfiddle link. I noticed that when you click the menu button, the little triangle pointing to the button only appears after the animation is complete. I would like the animation to start with the pseudo element and then show the drop-me ...

Utilizing objects from a JSON file within an HTML document

I'm currently in the process of creating a comprehensive to-do list, and I want to establish a JSON file that will link all the items on the list together. Despite my efforts, I find myself uncertain about the exact steps I need to take and the speci ...

The AJAX function fails to trigger the MVC controller method

I'm attempting to enable inline editing by cell, rather than by row, when double-clicking. Although the initial setup is working, it's not updating the record as expected - the "SaveCustomer" call to the controller isn't triggered. Can anyon ...

Guidelines for positioning an object to float in the bottom right of a separate tag

I am trying to position an image at the bottom right of a parent div. The CSS solution I found from another answer did not work as expected, so I had to use JavaScript to achieve the desired result. Is there a way to do this without using JavaScript? (Pl ...

Building a custom component library inspired by Vuetify: A step-by-step guide

I am looking to develop my own component library using Vuetify and then publish it on npm. Although Vuetify already has a standard Vue plugin installation and uses vuetify-loader, I believe creating components with it is a bit more complex compared to pla ...

Is it possible to highlight and copy text while using OrbitControls?

As I work on my Three.js project with OrbitControls.js, I've come across an issue where I am unable to select or highlight any text using OrbitControls. For example, you can try visiting this link: (try selecting the text "orbit control example" at ...

Set up a directory alias for the Grunt connect server

I have a set of folders in my project directory that I would like to make accessible using the Connect framework through a Grunt task. The structure of my folders is as follows... / /src index.jade /styles main.css /dist index.html /docs index.htm ...

Using JavaScript's AJAX to create conditional statements with the if-

Below is my JavaScript code that is meant to display a notification to the user if the PHP script below returns a MySQL select count result greater than 0: <script> $(document).ready(function() { function update() { ...

"Is there a virtual keyboard available that supports multiple inputs and automatically switches to the next input when the maximum length

Looking to build a virtual keyboard with multiple inputs that automatically switch to the next input field after reaching the maximum length. Currently having an issue where I can only fill the first input and not the second one. Any assistance in resolvin ...

Vue Router is failing to match a URL that contains numerous dynamic parameters

I've been working on adding a nested url to my routes and have encountered an issue with the last route in my code. Every other route seems to be functioning properly. I attempted to nest the urls using the children property, but it wasn't succe ...

The dynamic rendering of datasets is not supported in Material UI's <TableCell> component

I'm currently working on a table component that dynamically renders an item list based on a dataset. The Table component is made up of <TableHead/> and <TableBody/>. I am using the .map() method to dynamically assign values to the <Tabl ...

Issue with loading a Mongoose model

I'm facing a strange problem with NodeJS, require function, and mongoose. I have defined a user model schema as follows: let mongoose = require('mongoose'); let Schema = mongoose.Schema; let depositSchema = new Schema({ customer: Stri ...

I am configuring Jest in my Vite and TypeScript-powered React project

I am having trouble with the relative path of the file I imported in App.test.tsx. It keeps showing me this error message: Cannot find module '@/components/items/card.tsx' from 'src/__tests__/App.test.tsx' Below is the code snippet: // ...

Tips for overlaying an image on a div regardless of its height

(!) Although this question may seem repetitive, I have not been able to find a suitable solution in any of the previous 10 topics. I apologize for the inconvenience and am actively seeking a resolution to this unique situation; Allow me to outline the iss ...

Initiate a click event on an anchor element with the reference of "a href"

I'm currently facing an issue with clicking a href element on my HTML website. The click event doesn't seem to be triggered. CODE: HTML CODE: <div class="button" id="info" ></div> <ul id="game-options"> <li><a ...

Exploring methods to retrieve information from fs.readFile in vuejs3

I need some help with this code snippet I'm working on: //package.js "scripts": { "serve": "node readFile.js & vue-cli-service serve" }, //readFile.js const data = fs.readFileSync('path/file', 'utf-8 ...

Yii - The jQuery.fn.yiiGridView function is causing an error of undefined when attempting to use the update() function

Here is the code snippet for a widget I have: $this->widget('bootstrap.widgets.TbGridView', array( 'dataProvider' => $model->search(), 'filter' => $model, 'ajaxUpdate' => true, 'a ...