A guide to customizing node names using vue-slider-component

I am facing an issue with the vue-slider-component.

Below is the link to my current test module:

    template:`
    <div>
    <vue-slider
      v-model="value"
      :order="false"
      :tooltip="'always'"
      :process="false"
      :marks="marks"
      :width="600"
      ref="nodevalue">
      <template #tooltip="{ index }">            
        <div v-if="index === 1">🐰</div>
        <div v-else>🐢</div>
      </template>
    </vue-slider>
    <get-node-index>
    </get-node-index>                                
  </div>
    `,
    data: function () {
        return {
            columnvalue: [
                {text: 'cow', index: 0},
                {text: 'dog', index: 50},
                {text: 'cat', index: 80}
            ],
            value: [0, 50, 80],
            marks: {
              '100': {
                label: '🏁',
                labelStyle: {
                  left: '100%',
                  margin: '0 0 0 10px',
                  top: '50%',
                  transform: 'translateY(-50%)'
                }
              }
            }
          }
    }

new Vue({
  el: '#app',
  components: {
    VueSlider: window['vue-slider-component']
  },
  data: function() {
    return {
      columnvalue: [{
          text: 'cow',
          index: 0
        },
        {
          text: 'dog',
          index: 50
        },
        {
          text: 'cat',
          index: 80
        }
      ],
      value: [0, 50, 80],
      marks: {
        '100': {
          label: '🏁',
          labelStyle: {
            left: '100%',
            margin: '0 0 0 10px',
            top: '50%',
            transform: 'translateY(-50%)'
          }
        }
      }
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-slider-component@latest/theme/default.css">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="790f0c1c540a15101d1c0b541a16140916171c170d394a5749574d4a">[email protected]</a>/dist/vue-slider-component.umd.min.js"></script>

<div id="app">
  <vue-slider v-model="value" :order="false" :tooltip="'always'" :process="false" :marks="marks" :width="600" ref="nodevalue">
    <template #tooltip="{ index }">            
        <div v-if="index === 1">🐰</div>
        <div v-else>🐢</div>
      </template>
  </vue-slider>
</div>

Is there a way to place nodes on the slider using my column values?

Answer №1

The slider's index value does not represent the actual value of the slider, but rather its position in the slider array. Therefore, you need to update your data accordingly.

If you are using a version of Vue below 2.6, you will need to utilize slot and slot-scope. Regardless, the key components remain the same.

Adjusting your data structure:

columnvalue: [{
      text: 'cow',
      index: 0
    },
    {
      text: 'dog',
      index: 1
    },
    {
      text: 'cat',
      index: 2
    }
  ]

Updating the HTML to invoke a function:

<div>{{getText(index)}}</div>

Here is the function itself:

getText(index) {
    return this.columnvalue.find((v) => v.index == index).text
}
new Vue({
  el: '#app',
  components: {
    VueSlider: window['vue-slider-component']
  },
  data: function() {
    return {
      columnvalue: [{
          text: 'cow',
          index: 0
        },
        {
          text: 'dog',
          index: 1
        },
        {
          text: 'cat',
          index: 2
        }
      ],
      value: [0, 50, 80],
      marks: {
        '100': {
          label: '🏁',
          labelStyle: {
            left: '100%',
            margin: '0 0 0 10px',
            top: '50%',
            transform: 'translateY(-50%)'
          }
        }
      }
    }
  },
  methods: {
    getText(index) {
      return this.columnvalue.find((v) => v.index == index).text
    }
  }
})
#app {
  margin: 80px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-slider-component@latest/theme/default.css">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b1b2a2eab4abaea3a2b5eaa4a8aab7a8a9a2a9b387f4e9f7e9f3f4">[email protected]</a>/dist/vue-slider-component.umd.min.js"></script>

<div id="app">
  <vue-slider v-model="value" :order="false" :tooltip="'always'" :process="false" :marks="marks" :width="600" ref="nodevalue">
    <template slot="tooltip" slot-scope="{index}">
      <div>{{getText(index)}}</div>
    </template>
  </vue-slider>
</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

What causes the DOM to be updated upon each opening of the browser extension for Chrome?

Here is the default position: https://i.stack.imgur.com/tkWCA.png After checking it: https://i.stack.imgur.com/tdzbg.png When I click anywhere on the page to hide the dom extension output (without showing popup.html); However, when I reopen the extens ...

Utilizing JSON for the setAttribute() method

While I've made progress on this issue, I've encountered numerous confusing methods. The goal is to utilize the key:value pairs in attr{} for the setAttribute() function without relying on any framework. If anyone could provide a straightforward ...

HTML form submission with a grid of multiple choice options

I have created my own multiple choice grid: <div style="overflow-x:auto;"> <table class="w-100"> <tr> <td class="border"></td> <td class="border">Yes</td> <td class="border">No</ ...

Picture in a clear background without any alteration

Is there a way to create a background-color with opacity inside an image without affecting the image itself? The issue lies in the fact that the transparent background-color makes everything underneath it, including text and the image, transparent. Below ...

Creating a display of divs that flow from left to right in each row, and then stacking the rows from bottom to top using CSS and jQuery

My current dilemma involves a collection of divs that must be displayed in a specific order, but with a rather intricate layout. Essentially, this is the structure of my HTML: <div> <div class="box">1 (first in list)</div> <di ...

Every time I rotate my div, its position changes and it never goes back to

Trying to create an eye test by rotating the letter "E" when a directional button is clicked. However, facing an issue where the "E" changes position after the initial click instead of staying in place. Here is a GIF showcasing the problem: https://i.stac ...

Creating a custom script for a search field that retrieves information from an XML document

Attempting to create a script that iterates through an XML file, the provided code currently displays alerts but fails to show information when a valid value is entered into the search field. However, upon removing the error checks and keeping the final ...

Load prior state when the value changes with UseState in NextJS

In the development of my e-commerce application, I am currently working on implementing filters based on category and price for the Shop page. To handle this functionality, I have established the initial state as follows: const [filters, setFilters] = useS ...

The file upload process did not return a successful response for Ajax

Recently delved into the world of Ajax and encountered a perplexing issue. Here is the dilemma: I successfully upload a .csv file to the server. However, after the upload "success" in the ajax call fails to trigger a response. Neither does complete or er ...

Adjust color scheme of drop-down menu

Having trouble changing the background color for my drop down menu. I tried to change the color for the sub div but it's not working. Can anyone help me fix this issue? Here is the code snippet: http://jsfiddle.net/3VBQ6/4/ #nav li:hover ul.sub li { ...

Using a Javascript for loop to extract the initial event date from a Google Calendar

In my home.html file, the script below is responsible for: Connecting the website to a Google Calendar API Fetching dates and names of rocket launches My concern arises when a calendar for the same rocket has multiple launches in a single month. I aim fo ...

choose the li element that is located at the n-th position within

Need help with HTML code <div class="dotstyle"> <ul> <li class="current"><a href="javascript:void(0)"></a></li> <li><a href="javascript:void(0)"></a></li> <li><a href="javasc ...

Interacting with external domains through ajax queries

I'm encountering an issue with my javascript code that sends an ajax request, but I'm not receiving any response. Can anyone offer some guidance on how to troubleshoot this problem? Thank you! The URL I am attempting to retrieve is: Here's ...

Inject data from ajax into the body of the html document

Is it possible to retrieve values from an ajax call and insert them into the body of an HTML document? Here is an example: function check() { $.ajax({ url : '/check', datatype : 'json', async ...

Can markers be positioned on top of scroll bars?

Looking for a way to display small markers on the scrollbar of an overflow: scroll element, similar to features found in IDEs and text editors like this one: https://github.com/surdu/scroll-marker. I've considered using a pointer-events: none overlay ...

Building a dynamic URL in ReactJS from scratch

const selectedFilters = { category: "", mealtype: "lunch", cuisinetype: "Italian", dishType: "Pasta" } const apiUrl = `https://api.edamam.com/api/recipes/v2?type=public&q=${query}&app_id=${app_id}&app_key=${app_key}`; User ...

Resolving issues with setting up d3.js in the 'Creating a Custom Map' guide

Starting Mike Bostock's tutorial on creating a map, but facing some installation issues at the beginning. I am using Windows 8.1 for this. This is the specific part that's causing trouble: "To get started, you'll need the reference implemen ...

jQuery ajaxSetup: handling error retries for ajax calls is not possible

When using $.ajaxSetup(), I am faced with the challenge of making an AJAX request after refreshing a valid token in case the previous token has expired. The issue arises when attempting to execute $.ajax(this) within the error callback. $.ajax({ url: ...

Preventing special characters in an input field using Angular

I am trying to ensure that an input field is not left blank and does not include any special characters. My current validation method looks like this: if (value === '' || !value.trim()) { this.invalidNameFeedback = 'This field cannot ...

"An in-depth guide on parsing JSON and showcasing it in an HTML format

As part of my order processing, I am saving the order details into a JSON file named order_details.json. Here is an example of how the data is structured: [{ "uniqueID": "CHECKOUT_IE01", "orderID": "4001820182", "date": "06-02-2019 16:55:32.32 ...