Tips for concealing a div element when a mouse hovers over it in Vuejs

new Vue({
  el: '#mouse',
  data: {
    showByIndex: null
  }, 
  methods: {

  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="mouse">
  <div class="parent" v-for="i in 1" @mouseover="showByIndex = i" @mouseout="showByIndex = null">
    <div class="child-one">
      Some dummy text
    </div>
    <div class="child-two" v-show="showByIndex === i">
      Show me only on hover on "div.parent" element
    </div>
  </div>
</div>

Working example:- https://codepen.io/dhanunjayt/pen/XWgyqXW

When using the above code snippet, I successfully display text when hovering over a div element. However, there is a small issue where the first element does not behave as expected.

Answer №1

Do you like the code snippet below?

new Vue({
  el: '#mouse',
  data: {
    showByIndex: null
  }, 
  methods: {

  }
})
.parent {
  padding: 2em;
  background: violet;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="mouse">
  <div class="parent" v-for="i in 1" @mouseover="showByIndex = i" @mouseout="showByIndex = null">
    <div class="child-one" v-show="showByIndex === null">
      Some dummy text
    </div>
    <div class="child-two" v-show="showByIndex === i">
      Show me only on hover on "div.parent" element
    </div>
  </div>
</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

When connecting Django HTML variables, they are getting divided

I am currently working with a basic html layout that displays permissions in a table for each group. Each cell within the table contains a button, and I am attempting to have the name of the permission appear in a popover when hovering over each button. Ho ...

Unraveling the Mystery of Router Layers in Express.js

Trying to gain a deeper understanding of ExpressJS Routers. In the source code, I've discovered a separate module called Layer that is utilized with the router. This module appears to handle Regex operations for parameters. I've also observed t ...

Split total based on checkboxes toggled with JavaScript

I'm facing a challenge. I have a total sum of donations collected, for example, 10€. Additionally, there are various NGOs that one can select to donate to. Individuals have the option to toggle on/off which NGO's they wish to contribute toward ...

Sending an Ajax request to C# code

UPDATE After some research, I discovered what seems to be the "correct way" to handle the issue by using a combination of JSON.stringify and creating a model, as explained in this thread. I still can't figure out why the original approach didn't ...

Is it possible to customize the upload feature of ckeditor?

I attempted to utilize the upload feature in ckeditor with kcfinder. https://i.sstatic.net/mFv40.png Nevertheless, the current process requires clicking the "Send it to the server" button first for the image to be uploaded. I wish to eliminate this step ...

Navigation bar's active area does not span the full height

I'm facing some issues with the navigation bar on my responsive website. One issue is that the clickable area for the links does not extend to the full height of the nav bar, and I would like it to cover the entire height. Another problem arises whe ...

Identify a click event on a sortable element that has been dynamically added using the

I am currently working on creating 2 sortable lists, where the items are added using append(). Everything seems to be working perfectly fine, but I am facing an issue with making the items move between the lists upon clicking. For some reason, the click e ...

React.js router - struggles to clean up unsightly query parameters in the URL

I've been trying to eliminate the query string by following this solution: var { Router, Route, IndexRoute, IndexLink, Link } = ReactRouter; var createHashHistory = History.createHashHistory; var history = createHashHistory({queryKey: false} ...

The eslint-plugin-import package is struggling to distinguish between external and internal directories

Within my .eslintrc file, I have defined the following: "import/order": [ "error", { "alphabetize": { "caseInsensitive": true, "order": "asc" }, ...

Having trouble getting the three.js EffectComposer to function properly

Seeking guidance on using EffectComposer for postprocessing renders, as my basic setup doesn't seem to be rendering anything on the screen. Any ideas on what I might be missing? <!doctype html> <html> <head> <title>game& ...

I'm having trouble getting my canvas to work properly with my color selector

I have been working on implementing a color selector for my drawing application. The color selector appears to be functioning properly, however, when I actually try to draw, it only shows up in black. You can check out the code on this JSFIDDLE. If you lo ...

transforming unicode into regular characters prior to being presented on a webpage

I am currently utilizing the openinviter class to import contacts from emails. Sadly, it is showing Unicodes of non-English characters, like Polish, such as u0117 (and similar code types), instead of regular characters. Is there a way to convert these Unic ...

Guide: Fetching currentUser information using Vue.js, AWS Amplify, and MongoDB

I am currently developing a Vue.js application that combines the functionalities of AWS, MongoDB, and Express. For the authentication page of this app, I utilized aws-amplify and aws-amplify-vue. Upon successful login, the username metadata of the authenti ...

Updating the data displayed in the browser window with the response from a subsequent API call using JavaScript

Currently, I have three functions that retrieve JSON data from an API using HTML buttons and convert it to a string with stringify. The results are then displayed in a div, extending the current browser page with each new call. I am looking for a way to ha ...

Specifying the data type for a "promisifier" function in TypeScript or Flow

I have developed a function that effectively converts a callback-style function in Node.js to a promise-style function. export const promisify : PromisifyT = ( fn, ...args ) => { return new Promise( (resolve, reject) => { ...

The combination of GreaseMonkey and JQuery AJAX response is unable to persist through callbacks in any way

Despite being asked about before, it seems that the solutions provided three years ago no longer work for my current issue. This problem involves creating a Greasemonkey script that needs to fetch a link from a page, request the linked page (which is on th ...

What is the best way to showcase the current element using jQuery?

I have this example: link HTML CODE: <div class="common-class"> <div class="trigger"> <span class="plus">+</span> <span class="minus">-</span> </div> <div class="show"></div> </div&g ...

Updating the state of a Next.JS router component with React.JS: A step-by-step guide

I've implemented a toggleswitch in my app that changes its state based on the dynamic URL parameters. For instance, if the URL includes a parameter named followType set to following (e.g. https://www.example.com/home?followType=following), I want the ...

Moving an image between different routes using a query

enter image description here I am currently working on a project where I need to take an image input file from the user and display it in another route. To achieve this, I am using query parameters. Issue: However, despite my efforts, the image is not bei ...

Mastering regular expressions in TypeScript

My goal is to perform linting on staged files that are either .ts or .tsx and located within the src folder. I am aware that for selecting all js files one can use "*.js": [--list of commands--] inside the lint staged property. I'm curious to learn m ...