How to overcome the issue of Vue.js mobile router-link being blocked by v-on:mouseover

Here is a for list snippet:

<li
  class="projects-item"
  v-for="project in filteredProjects"
  :key="project.id"
  v-on:mouseover="displayHoverInfo($event, project)"
  v-on:mouseleave="hover = false"
  >
  <router-link v-bind:to="'/project/' + project.slug">

In JavaScript:

displayHoverInfo(event, project) {
  this.hover = true;
  this.hoveredProject = project;
  console.log(event);
}

Everything works fine on desktop, but on mobile (tapping), only the v-on:mouseover/v-on:mouseleave events are triggered.

Answer №1

I found the solution here: https://forum.vuejs.org/t/how-to-disable-mouseover-on-mobile/37335

To disable the mouseover and mouseleave events on mobile devices, you can also check if it's a mobile or tablet device using the user agent.

<li
  class="projects-item"
  v-for="project in filteredProjects"
  :key="project.id"
  v-on:mouseover="isMobile ? null : displayHoverInfo($event, project)"
  v-on:mouseleave="isMobile ? null : hover = false"
  >
new Vue({
  el: "#app",

  data: {
    isMobile: false,
    hover: false
  },

  methods: {
    mq() {
        this.isMobile = window.matchMedia('(max-width: 400px)').matches;
    },
    displayHoverInfo($event, project) {
        // your method implementation
    }
  },

  created () {
    // get initial value
    this.mq()
    // listen for resize events
    window.addEventListener('resize', this.mq)
  },

  beforeDestroy() {
    window.removeEventListener('resize', this.mq)
  }
})

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

Angular's observable function is not providing a complete response

In my Angular component, I have a function that is called from a template. This function returns an Observable of type string, but unfortunately it only returns the `data` variable. How can I modify it to return `dateNew[0] + " de " + data + " de "+ dateNe ...

My Angular project is experiencing issues with Socket.IO functionality

After successfully using a post method in my endpoint, I encountered an error when integrating it with socket io. The error pertained to a connection error and method not being found. Any help or source code provided would be greatly ap ...

Sorting technique failing to reorganize list

I'm currently troubleshooting why my sorting function is not functioning as expected. My goal is for it to operate similarly to this example: https://codepen.io/levit/pen/abmXgBR The data I am working with is retrieved from an API: <BookCard v-fo ...

Tips and tricks for personalizing an npm package in vue.js

I've been working on customizing a multiselect package to incorporate tab events in vuejs, but so far I haven't seen any changes reflected. I'm looking for guidance on how to modify a library within Vue. My approach was to navigate to the n ...

Struggling to capture a "moment in time" of a form without losing any of the data

My form is highly dynamic, with interacting top-level elements triggering a complete transformation of the lower-level elements. I needed a method to maintain state so that if users partially entered data in one category, switched temporarily to another, a ...

Detecting the State of the Keyboard in Ionic 2

Seeking an easy way to determine if the mobile device keyboard has been opened or closed using Ionic2 and Angular2. Is there a 'keyboard-open' or 'keyboard-close' class that Ionic sends to the body/html? ...

What is the process for customizing the arrow of a <select> dropdown menu exclusively?

Here is the code for a dropdown menu: <select id="dropdown"> <option value="">Go to page...</option> <option value="http://stackoverflow.com">CSS-Tricks</option> <option valu ...

Can someone assist me in retrieving the information stored within an object?

I'm currently working on a Discord bot and I am in need of the user ID, specifically 'xxx', but I'm unsure of how to retrieve it. Here is what I have tried so far: n.mentions.users.User. -- n.mentions.users.User() This is what my code ...

Having trouble creating a polygon from JSON in ESRI ArcGIS Javascript framework?

Can anyone assist with understanding the issue of trying to draw a polygon using the ESRI ArcGIS Javascript API? The image, JSON string, and code snippets provided below outline the code, console output, and expected behavior. Any help would be greatly app ...

Ensuring a correct dismount of a React component

Apologies for the lack of specificity in the title of this inquiry. Upon executing the code snippet below, I encountered the ensuing warning: Warning: setState(...): Can only update a mounted or mounting component. This typically indicates that you call ...

Implementing div elements in a carousel of images

I've been working on an image slider that halts scrolling when the mouse hovers over it. However, I'd like to use div tags instead of image tags to create custom shapes within the slider using CSS. Does anyone have any advice on how to achieve th ...

Tips for Utilizing Both getElementByID and getElementByTagName Functions in JavaScript

Hi! I'm a beginner in JavaScript and I've managed to retrieve some data using getElementById. Now, I want to extract a specific part using getElementsByTagName. document.getElementById('titleUserReviewsTeaser').innerHTML; " < ...

Troubleshooting: How to resolve the issue of "Error [ERR_HTTP_HEADERS_SENT]: Unable to set headers after they have been sent to the client"

* **> const PORT=8000 const express = require('express') const {v4:uuidv4}=require('uuid') const bcrypt =require('bcrypt') const jwt =require('jsonwebtoken') const cors=require('cors') const {MongoClie ...

JavaScript 3D Arrays

Is there a way to create a 3D array similar to runes['red'][0]['test']? If so, how can I accomplish this? var runes = {} runes['red'] = [ 'test': ['loh'] ] runes['blue'] = {} runes[&apo ...

Dividing a string using jQuery

What is the best way to extract numbers from strings using jQuery? Mode1 2Level In jQuery, how can I retrieve only the numerical values from the strings shown above? The strings could be variations like Mode11, Mode111, 22Level, 222Level, where the char ...

How about setting variables in Vue router as an alternative to controlling component visibility?

Utilizing URL parameters to set variables in my Vue application is a goal of mine. While I initially thought vue-router would be the perfect solution, it appears to be more catered towards handling the showing and hiding of components within a router-view ...

Adding a proptype for a setState method in React components

I am currently developing a reusable component for a project. This particular component includes user and setUser as props, much like the example provided below. const UserComponent = ({ user, setUser }) => { const calcHandler = useCallback(() =& ...

Is there a way to exclusively view references of a method override in a JS/TS derived class without any mentions of the base class method or other overrides in VS Code?

As I work in VS Code with TypeScript files, I am faced with a challenge regarding a base class and its derived classes. The base class contains a method called create(), which is overridden in one specific derived class. I need to identify all references ...

Unexpected errors causing havoc in my internet browser

I am facing difficulties uploading large files (~ 2 GB) on my server. To prevent crashes caused by huge files, I have removed the bodyParser from Express. However, the crash error occurs randomly, making it challenging to pinpoint the exact cause. The cod ...

Repeated information in HTML tables

I am currently working with two HTML tables and two sets of JSON data. Initially, I load one table with the tableData which has a default quantity of 0. In my HTML form, there are three buttons - save, load draft, and edit. Upon clicking on load draft, I p ...