Display a particular element when hovered over

Is there a way to make only individual elements pop up on hover instead of all of them at once?

items: [{
    item: "Book",
    info: "Lorem ipsum",
    displayInfo: false
  },
  {
    item: "Pen",
    info: "Lorem ipsum",
    displayInfo: false
  },
  {
    item: "Paper",
    info: "Lorem ipsum",
    displayInfo: false
  }
]
<ul>
  <li v-for="(item,index) in items" v-bind:key="index" @mouseover="item.displayInfo=true;" @mouseleave="item.displayInfo=false">{{item.item}}
    <p v-if="item.displayInfo">{{item.info}}</p>
  </li>
</ul>

Answer №1

It seems like your code is correct after all. By adjusting the deleteNote property of the elements, we can observe if it functions more accurately. This approach ensures that only the note of the currently hovered element is displayed:

new Vue({
  el: '#app',
  data: {
    lists: [{
        fruit: "Apple",
        note: "aa",
        deleteNote: false
      },
      {
        fruit: "Pear",
        note: "pp",
        deleteNote: false
      },
      {
        fruit: "Eggs",
        note: "gg",
        deleteNote: false
      }
    ]
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <ul>
    <li v-for="(list,index) in lists" v-bind:key="index" @mouseover="list.deleteNote=true;" @mouseleave="list.deleteNote =false">{{list.fruit}}
      <p v-if="list.deleteNote">{{list.note}}</p>
    </li>
  </ul>
</div>

Answer №2

Each delete button is connected to a single flag for deletion.

You can implement it like this:

<ul>
 <li v-for="(list,index) in lists" v-bind:key="index" @mouseover="list.deleteNote=index;" @mouseleave="list.deleteNote = -1">{{list.fruit}}
  <p v-if="list.deleteNote === index">{{list.note}}</p>
 </li>
</ul>

On hover, the current index is assigned to deleteNote, and on mouseout, an invalid index (-1) is assigned. This way, each delete button corresponds to its respective index.

Answer №3

It seems like the codesandbox feature on StackOverflow does not support vue.js, so I made some adjustments to the JavaScript in the following fiddle. According to the Vue list rendering documentation, the entire list needs to be wrapped as a variable.

You can check out my fiddle with your code and the expected result here: https://jsfiddle.net/gve4s87L/

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

I'm attempting to utilize a basic webcam capture upload feature, but it seems that the upload function is not functioning properly

UPDATE: This is the complete code that I simply copied and pasted. <!DOCTYPE HTML> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script language="JavaScript" type="text/javascrip ...

The tooltipShowDelay setting within AG Grid does not seem to be functioning as expected

Currently, I am utilizing AG Grid version 26.2 in conjunction with Vue 2. My objective is to eliminate the delay in rendering tooltips by setting tooltipShowDelay to 0 for an instantaneous display. Initially, the first render takes approximately ~2 secon ...

What are the steps to effectively populate a mongoose schema?

In my application, I have a model for people: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const PersonSchema = new Schema({ name: String, cars: [{ type: Schema.types.ObjectId, ref: 'Cars' }] }); ...

Managing options post initialization in egjs-flicking: A comprehensive guide

In my Vue2 project, I am currently utilizing egjs-flicking. I am looking for a solution to implement different align options based on the screen size (mobile or desktop). Is there a method to accomplish this without having to destroy or reinitialize the ...

The hydration error in next js is causing this code to malfunction

Why am I encountering a hydration error with this code in NextJS? The Items variable is an array of ReactNode's. Any suggestions for an alternative approach? I've searched extensively for information but haven't found anything related to Nex ...

Error: Attempting to assign value to the 'innerHTML' property of null in a Wordle clone with local storage

While developing a Wordle-inspired game for my website, I decided to utilize Local Storage to store the user's progress. Everything seemed to be working smoothly until an unexpected error occurred: "Uncaught TypeError: Cannot set properties of null (s ...

What is causing the check box in the simple_form view to consistently return a value of 1 when checked or unchecked in rails 3.2?

A checkbox with the name "need_delivery" is used to determine whether the next two text boxes should be displayed. These two text boxes are enclosed within a div with the id of task_request_delivery. Below is the code snippet in the simple_form view named ...

Currently in the process of transitioning to vue3 with <script setup>, encountering issues with the functionality of computed

I recently migrated my Vue2 script to Vue3 using <script setup>. However, I am facing an issue where the computed function does not work even when seriesData is changed. Currently, my source code looks like this and it is functioning correctly: < ...

Clicking on the modal button causes the code to run multiple times in JQuery and JavaScript

Hello, I'm experiencing an issue where the code inside a modal is being executed multiple times when the modal button is clicked. For example, if I click the modal button once, the code runs once; if I click it twice, the code runs twice, and so on. ...

Ways to implement StackNavigator along with Redux?

Is there anyone who can assist me in integrating StackNavigator and Redux? It seems straightforward, but I'm encountering issues. index.ios.js import React from 'react' import { AppRegistry } from 'react-native' import { Provi ...

Monitor $localStorage for any modifications

Utilizing the ngStorage module, which can be accessed at this link: https://github.com/gsklee/ngStorage In order to maintain a lastSeenId for a real-time social feed in my hybrid app (Laravel/AngularJS), I am storing it in localStorage instead of $scope. ...

Having trouble extracting a JSON object from a POST request in Express v4 with the help of body-parser?

Currently, I am delving into the world of server-side code and learning about Node.js and Express. However, I am facing some challenges when it comes to receiving and parsing a JSON object sent from a POST request. Despite checking various resources (linke ...

Error encountered in Node/Express application: EJS partials used with Angular, causing Uncaught ReferenceError: angular is not defined

I seem to be missing something important here as I attempt to incorporate ejs partials into a single-page Angular app. Every time I try, I encounter an Uncaught ReferenceError: angular is not defined in my partial. It seems like using ejs partials instead ...

Implement AJAX and PHP to submit form data along with the page ID and session information

I am currently developing a school book library website project that allows students to browse and select books, as well as send requests to the librarian to borrow them. However, I am still learning jQuery and facing some challenges in handling issues. H ...

Creating an object efficiently by defining a pattern

As a newcomer to Typescript (and Javascript), I've been experimenting with classes. My goal is to create an object that can be filled with similar entries while maintaining type safety in a concise manner. Here is the code snippet I came up with: le ...

Obtaining the pathname in a NextJS file like _document.js is a matter of accessing

I'm looking to retrieve the current URL path in my /page/_document.js file. I've created a class and my goal is to implement a conditional statement based on this value. Below is the code snippet (similar to the example provided in NextJS docume ...

Is there a reason for the absence of the Revit category attribute in the JSON response retrieved from the GET request :urn/metadata/:guid/

After receiving the information from the endpoint regarding Revit Models uploaded to my bucket, I noticed that the JSON response contains multiple objects. These objects seem to represent Revit elements, each with all parameters except for the Revit Categ ...

Express framework in NodeJS encounters an undefined header error

Utilizing Microsoft Flow to dispatch an HTTP POST request to my server, the request body includes a custom header known as "Email-To" with a string value. Here is the body: { "$content-type": "multipart/form-data", "$multipart": [ { "headers ...

What is the best way to create a non-reactive value in Vue.js?

In my Vue.js app, I am facing an issue where an array value is becoming reactive even though I want it to remain un-reactive. The array should only be updated when a specific "refresh" action is completed. However, every time a new value is assigned to the ...

What are some ways to prevent screen flickering when combining Vue with Rails?

Recently, we've been incorporating Vue into our Rails app. This integration has led to flickering Capybara/rspec tests due to race conditions where some or all Vue elements aren't fully rendered when the next Capybara action takes place. The erro ...