Activate Vuetify to toggle a data object in an array list when the mouse hovers over

I'm currently working on a project where I need to toggle a Vuetify badge element for each item in an array when the containing div is hovered over.

While I've been able to achieve a similar effect using CSS in a v-for loop with an array list, I'm struggling to figure out how to accomplish the same outcome with Vuetify components. Despite searching through various resources like:

  1. First Link
  2. Second Link
  3. Third Link

I still haven't found a solution that fits my specific needs.

You can view the current implementation I have in this CodePen Link. The issue lies in the fact that all badge elements are being triggered when any one of the elements is hovered over, rather than just the one being hovered on.

Here's a snippet of the HTML code:

  <template>
   <div id="app">
      <div>My favourite fruit is <b>{{favouriteFruit}}</b></div> <br>

   <div v-for="(dataArray, index) in testArray" @click="setCurrent(dataArray.name)">
      <v-badge
              :color="computedFavFruitColor[index]"
              right
              v-model="show"
      >
         <template v-slot:badge>
            <span><v-icon color="#ECF0FF">{{computedFavFruit[index]}}</v-icon></span>
         </template>
        <div @mouseover="show = true" @mouseleave="show = false">
           {{dataArray.name}}
        </div>
      </v-badge>

   </div>
   </div>
</template>

If anyone has suggestions or further guidance on how to resolve this issue, it would be greatly appreciated.

Answer №1

If you want to target the element you hover on instead of counting for every item globally, keeping track of the index of the item you hover can be a good solution. Check out this code snippet for an example: https://codepen.io/reijnemans/pen/JjPrayp?editors=1010

    <div v-for="(dataArray, index) in testArray" @click="setCurrent(dataArray.name)">
      <v-badge
              :color="computedFavFruitColor[index]"
              right
      >
         <template v-slot:badge>
            <span v-if="show == index"><v-icon color="#ECF0FF">{{computedFavFruit[index]}}</v-icon></span>
         </template>
        <div @mouseenter="show = index" @mouseleave="show = null">
           {{dataArray.name}}
        </div>
      </v-badge>

   </div>

Remember to use show = null instead of show = true in the data block of vue

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

Struggling with setting up Chrome options using Selenium WebDriver in JavaScript?

Encountering an issue while attempting to access a specific website using Selenium WebDriver in JavaScript with the Chrome browser. In the provided code snippet, the browser driver is initialized; however, there seems to be a problem when utilizing setChro ...

Trouble arises with the chrome extension code for retrieving tweets from Twitter

I'm currently working on developing a Chrome extension that will display tweets featuring the hashtag perkytweets within the extension's popup. However, I'm facing an issue where nothing is being displayed. Let's take a look at the cod ...

Ways to retrieve particular items/properties from the JSON response string

Is there a way to extract and display only the first 3 items from my JSON data instead of the entire string? Below is the code I am currently using to loop through and display my records: <tr v-for="(list) in myData" v-bind:key="list.ema ...

Is it possible to pre-select a value in a PrimeVue Dropdown component?

Situation: Currently, I am incorporating PrimeVue into a Vue.js project. Within this setup, there is a dropdown component sourced from PrimeVue, utilizing an array of objects. The structure of the dropdown component appears as follows: <template #positi ...

Create a simulated reload of the window location using sinon

Currently, I am working on creating tests using sinon for a specific section of Vue code that triggers a page reload with window.location.reload();. Even though the code functions properly, the test is encountering a failure with the error message Error: ...

Creating a button that allows updates without refreshing the page can be achieved by implementing

Here are the items I have: <table> <tr> <th> id </th> <th> name </th> <th> update </th> </tr> <tr> ...

Removing an object from nested JSON based on a condition using jQuery with the help of AngularJS

I have a JSON object stored in the variable $scope.bbTreeData. I'm trying to delete any objects where the flag is set to false. While I can navigate through the nested JSON object, I'm unsure how to properly remove the object. Any suggestions? [ ...

JavaScript - returning a false error

I'm experiencing an issue with my form validation function that is supposed to check for empty fields by looping through the form elements. Here's the code snippet: function validateForm(ourform){ var formElements = document.getElementById(our ...

Tips for executing a function only once within the animation loop in Three.js

Is there a way to call a function only once when a certain condition is met in Three.js? I am currently sampling the frames per second (FPS) to send it to an external service. The FPS is sampled and averaged over time, and the average value is sent after 1 ...

Choose from a variety of video play options

Being new to javascript, I've successfully combined two functions that control video playback, but they seem to be conflicting with each other. The first function is designed to offer custom pause and play controls for the video // VIDEO CONTROLS STA ...

Showing the initials of a user at the top of an SVG using ReactJS

I require the user's initials to be displayed on the avatars as a grey circle with those initials. I have the function ready, but I am unsure of how to implement it in the JSX code for the Dropdown menu (using SemanticUI library). Any suggestions? co ...

Is React capable of storing and recognizing images within its system?

As a junior developer, I find this aspect confusing. Specifically, does reusing the same image on multiple routes in React result in the user downloading it more than once in the browser? I am striving to understand whether using the same image repeatedly ...

Parsing the CSV file contents according to the specified columns

Currently, I'm involved in a project using AngularJS where I need to extract data from a CSV file column by column using JavaScript. So far, I've successfully retrieved the CSV data and displayed it in the console. While I've managed to sepa ...

Tips for troubleshooting a 422 (Unprocessable Entity) Error Response in a Vue/Laravel project

I'm currently struggling to connect the frontend of my simple Vue 3 and Laravel 8 contact form project with the backend. No matter what data values I pass, whether it's null or not, I keep getting a 422 (Unprocessable Entity) response without any ...

Does Vue have an equivalent to React Three Fiber (R3F)?

As I dive into learning three.js, I am curious if there is a Vue equivalent to React Three Fiber. I prefer not to learn another framework just to use this tool. I tried searching for it online but only came across a GitHub repository in Chinese that doesn ...

What is the best way to expand an object without including any null values?

Imagine a scenario where there is an object: var user = { "Name": "Dan", "Age": 27, "Hobbies": null }; and it needs to be merged with the following base object to ensure all necessary properties are present: var base = { "Name": nul ...

The click listener triggers a single time when a render method is nested within it

When I have a click listener on a button that resets the innerHTML of a div with a render method, the listener fires every time I click if I take out the render function. However, if the render function is included, the listener does not fire multiple time ...

Pass multiple variables as input to a function, then query a JSON array to retrieve multiple array values as the output

My JavaScript function contains a JSON array, where it takes an input and searches for the corresponding key/value pair to return the desired value. I am attempting to input a string of variables like this: 1,2,3,4,5 Into this function: function getF(f ...

It appears that Javascript variables are behaving in a static manner

I am currently building a PHP website with a registration page for users. I am implementing the LOOPJ jQuery Autocomplete script from to enable users to select their country easily. In this process, I encountered an issue where the value of another field ...

Primeng - Concealed dropdown values within a scrollable table header

Recently, I integrated Primeng p-table with a filter and frozen column feature (with one column being fixed while the others are movable). However, I encountered an issue with the select dropdown in the header. When I try to open the dropdown, the values a ...