最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuetify v-slider - execute function after change of value (v-slider) - Stack Overflow

programmeradmin5浏览0评论

I am trying to execute a function when the v-slider is used (using dojo/on), but my approach doesn't work. Do you have any idea what I should change?

<div id="app">
  <v-app>
    <v-content>
      <v-container>
       <v-slider v-model="sliderValue"
                    id="sliderId"
                    v-on:input="sliderInput"
                    :max="2018"
                    :min="1990"
                    step="1"
                    thumb-label
                    ticks></v-slider>
      </v-container>
    </v-content>
  </v-app>
</div>


new Vue({
  el: '#app',
  data: () => ({
    sliderValue: 1990
  }),
  methods: {
    sliderInput (e) {
      this.sliderValue = e
      return this.sliderValue
    }
  },
  mounted  () {
    require(["dojo/on"], function(on){
      var slider = document.getElementById('sliderId')
      var vm = this
      function SomeFunction() {
        console.log('SomeFunction executed')
      }
      on(slider, 'change', function (event) {
        var xyz = vm.sliderValue
        SomeFunction(xyz)
      })
    })
   }
  })

I am trying to execute a function when the v-slider is used (using dojo/on), but my approach doesn't work. Do you have any idea what I should change?

https://codepen.io/hjmd/pen/bjGLoJ

<div id="app">
  <v-app>
    <v-content>
      <v-container>
       <v-slider v-model="sliderValue"
                    id="sliderId"
                    v-on:input="sliderInput"
                    :max="2018"
                    :min="1990"
                    step="1"
                    thumb-label
                    ticks></v-slider>
      </v-container>
    </v-content>
  </v-app>
</div>


new Vue({
  el: '#app',
  data: () => ({
    sliderValue: 1990
  }),
  methods: {
    sliderInput (e) {
      this.sliderValue = e
      return this.sliderValue
    }
  },
  mounted  () {
    require(["dojo/on"], function(on){
      var slider = document.getElementById('sliderId')
      var vm = this
      function SomeFunction() {
        console.log('SomeFunction executed')
      }
      on(slider, 'change', function (event) {
        var xyz = vm.sliderValue
        SomeFunction(xyz)
      })
    })
   }
  })
Share Improve this question edited Jul 10, 2018 at 15:36 asked Jul 10, 2018 at 15:24 user8643181user8643181 3
  • Have you tried adding v-on:change attribute? I don't see the point of using dojo here – barbsan Commented Jul 11, 2018 at 7:11
  • 1 Vuetify's v-slider has both @change and @input events. @change is normally triggered when the slider losses focus, whereas @input will trigger after the value changes. – Neil Merton Commented Jun 12, 2020 at 19:27
  • 1 The codepen is missing. – mareoraft Commented Jun 12, 2020 at 20:44
Add a ment  | 

3 Answers 3

Reset to default 3

I don't know if you have got the answer to it but if not, you can use: @change="function"

I have no idea how the vuetify library works neither the dojo, but I'm familiar with the VUE. The v-model is essentially syntax sugar for updating data on user input events, you could replace it with v-bind and v-on:input. So it's wrong you bind sliderInput with input event again.

In Vuetify 3 you need to use event "end" In your example it would be like this @end="sliderInput"

发布评论

评论列表(0)

  1. 暂无评论