Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach an onchange listener on a noUiSlider

I have a noUiSlider in my Project for which I have an @click listener.

<template>
  <div ref="slider" @click="getSliderVal()"></div>
</template>

<script>
import noUiSlider from 'nouislider';
import 'nouislider/distribute/nouislider.css';

export default {
  mounted() {
    noUiSlider.create(this.$refs['slider'], {       
      start: [0],
      connect: true,
      range: {
        'min': -1,
        'max': 1
      }
    })
  },    
  methods: {
    getSliderVal(){
      let a = this.$refs['slider'].noUiSlider.get()
      console.log(a)
    }
  }
}
</script>

I need the value of the Slider in REAL-TIME for which an @change listener should ideally work but it's not working here. Am I making a mistake here or is there an alternative way?

like image 365
Manan Sharma Avatar asked Aug 31 '25 17:08

Manan Sharma


1 Answers

You can use updateOptions method...

await this.slider_.noUiSlider.updateOptions({
    start: [that.startTime, that.endTime],
    range: {
      'min': 0,
      'max': Math.round(this.duration * 100) / 100
    }
  }, true);
like image 55
Rohit Tagadiya Avatar answered Sep 02 '25 07:09

Rohit Tagadiya