When an icon is hovered over in Vue, a text box popup will be displayed

Working on a personal project that requires obtaining the status of all devices within a unit. The status, along with the device name, is returned in an array from the function deviceStatus(). If all devices are currently marked as ON, the home icon next to the unit.id will turn green. Conversely, if all devices within the unit are marked as OFF, the home icon will turn red. The code provided below functions correctly for this purpose.

Seeking assistance in displaying the array returned from deviceStatus() as a text box popup when hovering over the 'home' icon. Specifically confused about implementing the mouseover event and any guidance would be greatly appreciated.

<template>
  <div>
    <div class="d-flex flex-row align-items-center py-2 px-2">
      <h1 class="display-1 unit-status m-0">{{ unit ? unit.id : null }}</h1>
      <font-awesome-icon
          icon="home"
          :style="deviceStyling"
          class="tab-icon mx-2"
          size="lg"
          id="unit-info"/>
    </div>
</template>

<script>

export default {

  computed: {
    deviceStatus() {
      const device = this.unitDvc(this.currentSite.id);
      return device.map(dv => {
        const status = this.deviceStat(dv.device_id);
        return { name: dv.name, status };
      });
    },
    deviceStyling() {
      var turnedOn = null;
      var turnedOff = null;
      for (var i = 0; i < this.deviceStatus.length; i++) {
        if (this.deviceStatus[i]['state'] == 'on') {
          turnedOn = turnedOn + 1;
        } else {
          turnedOff = turnedOff + 1;
        }
      }
      if (turnedOn == this.deviceStatus.length) {
        return { 'color': `green` };
      } else if (turnedOff == this.deviceStatus.length) {
        return { 'color': `red` };
      }

    }
  },
</script>

Answer №1

Make sure you've installed the necessary v-tooltip package

npm install --save v-tooltip

and included it in your application

import Vue from 'vue'
import VTooltip from 'v-tooltip'

Vue.use(VTooltip)

You can then utilize the directive in your component:

<font-awesome-icon
          v-tooltip="'Displaying status: ' + deviceStatus.name"
          icon="home"
          :style="deviceStyling"
          class="tab-icon mx-2"
          size="lg"
          id="unit-info"/>

Answer №2

Incorporating HTML and JavaScript, a useful attribute to consider is TITLE. This attribute functions by triggering a mouseover event.

To learn more, visit: Title - MDN

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 deactivate a text box within a form that is dynamically generated using Angular

I have encountered an issue with disabling the textbox inside my dynamic form in AngularJS after clicking a button. My code works perfectly fine for disabling textboxes outside the dynamic form, but when I try to target the ID of the textbox within the dyn ...

Incorporate dynamic variables into your HTML code using jQuery or JavaScript

I'm struggling to generate HTML code from JavaScript/jQuery within an HTML template rendered in Django. I need to append HTML code and also insert some values in between. Currently, I am using a basic string append method like this: var features =[&ap ...

Three.js: Modifying values within dat.GUI is not allowed

I have added a "comboBox" to my dat.GUI instance in order to select possible values. However, when I run my application, the dat.GUI appears with the comboBox but it seems to be frozen - I cannot change its default value. Below is the code snippet that dem ...

Invoke a function within a distinct context using a loop

I'm currently using a script where a function is called for each element on the page. It works fine when I make separate function calls, but if I try to call the function with a unique selector, it doesn't work as expected. Is there a way I can c ...

Exploring the relationship between $resource and controllers

I am currently working on deciphering the code snippets below. From what I gather, there are three resource objects - CategorySrv, ArticleSrv, and SearchSrv that interact with REST server data sources. app.factory('CategoryService', function($re ...

Local server displaying 'Undefined' instead of the unique identifier

My goal is to create a script that will fetch a unique ID from a database when clicked. Despite searching various forums for a solution, I haven't been successful in finding one. <?php $table = mysqli_query($conn ,'SELECT * FROM co ...

Guide for implementing pagination on a lengthy list with React MaterialUI

I'm currently working on a project using react and MaterialUI to create a list with filter functionality. The list will be populated with data from an Http request and may contain a large number of items. I was researching pagination in the MaterialUI ...

Error: Docker/Next.js cannot locate module '@mui/x-date-pickers/AdapterDateFns' or its respective type definitions

When I run the command npm run build, my Next.js application builds successfully without any issues. However, when I try to build it in my Dockerfile, I encounter the following problem: #0 12.18 Type error: Cannot find module '@mui/x-date-pickers/Ada ...

Creating a dynamic table using JQuery to display data from a JSON object with a flexible number of fields

Dear all, I must apologize for any messy coding errors as this is my first attempt at something like this and I am learning on the go. I am currently working on using JQuery's $.each() method to iterate through a JSON object retrieved via an Ajax cal ...

Tips for Successfully Sending Vue Data in Axios POST Call

I'm struggling to pass Vue data to an axios.post request. Using the Vue template doesn't seem to work. How can I successfully pass the Data? Here is my Code: <body> <div id="app" class="container"> <div> ...

Searching for an element with a changing name using jQuery - Struggling with quotes

Looking to navigate my DOM based on the value of an option in a select box. The value of "searchkey" can vary based on user input, for example: searchkey = dell'anno searcheky = dell"anno These options, particularly the first one, can cause issues ...

What is the best approach to designing a dynamic class toggler for a React sidebar?

I am trying to add a specific class to a clicked link within a sidebar. While this works for one link, when I attach the handler to another link and click it, both links get assigned with the new class. Is there a way to make this functionality more like ...

Include a hyperlink in an email using PHP

I am currently using an HTML form textarea along with PHP to send emails through my website. My question is, how can I successfully insert a link into the email message body? I attempted to do it like this: <a href="http://www.xxxxx.com/">Visit the ...

How to change a POST request to a PUT request using Express and keeping the

In my express app, I have set up two routes like this: router.post('/:date', (req, res) => { // if date exists, redirect to PUT // else add to database }) router.put('/:date', (req, res) => { // update date }) W ...

Is it possible for a CSS code to be universally effective across all PHP files by setting style.css in header.php and then including header.php in each of the other PHP files?

Let me confirm, the code snippet from the header.php file is as follows: <link rel="stylesheet" href="style.css"> If I include the following code in every other php file: include 'header.php'; Will all the files have access to style.css ...

AngularJS Form Validation Error Handling

I am in the process of implementing Form Validation using AngularJS, and I have come across a scenario involving ng-class that is confusing me. Could someone please explain why they are utilizing ng-class in this manner? The presence of a map and an arra ...

Recurring loop in React while making a GET request

I'm facing an issue with my React code. I need to send a GET request to the backend, which will return a boolean value in response. Within the useEffect hook, I want to check this boolean value and if it's TRUE, display something in the console. ...

Why are users not visible in the Node.js application?

Good day! I am a newcomer to this community and I'm hoping to get some guidance in the right direction with my inquiries. Recently, I came across some code on Github that I am trying to improve upon. The code can be found at https://github.com/voroni ...

How to send parameters through the Google Maps API URL using Vue.js

When using $router.push(), I receive two parameters: {{ this.$route.params.lat }} and {{ this.$route.params.lng }}, which are latitude and longitude coordinates. To access a Google Maps URL, I need to include both of these parameters: https://maps.googlea ...

JSON script containing the variable "url"

After spending days messing around, I've been learning javascript and jquery for a few weeks now. It's been going well, but there are some hurdles... For a mobile app I'm working on, I'm trying to retrieve the coordinates. Displaying t ...