首页 > 解决方案 > 如何在 Laravel 5.6 中使用 vue-slider-component

问题描述

我想在我的面板中添加一个滑块。我已安装

npm install vue-slider-component --save

然后我创建了一个新组件并注册了app.js

在我的 Slider.vue 组件中,我添加了 startet 模板

<template>
  <div>
    <vue-slider ref="slider" v-bind="options" v-model="value"></vue-slider>
    <h3><small>Value: </small>{{ options.value }}</h3>
  </div>
</template>

并导入了 vueSlider

<script>
  import vueSlider from 'vue-slider-component'

  export default {
    components: {
      vueSlider
    },

    data() {
      return {
        options: {
          value: 5,
          width: 'auto',
          height: 6,
          direction: 'horizontal',
          dotSize: 16,
          eventType: 'auto',
          min: 5,
          max: 100,
          interval: 5,
          show: true,
        }
      }
    },
  }
</script>

我得到了滑块。不幸的是,我不能滑动它并在开始时立即获得 maxValue。就像在这张照片中一样 在此处输入图像描述 ,就是这样。我在哪里点击都没关系,它什么也不做。当我想更改诸如更改 dotSize 之类的选项时,它也什么也不做。

我注意到当我打开控制台(F12)时它工作得很好。

滑块包装在 bootstrap 3 面板中。

我错过了什么?

更新 1:

我将值拉到选项之外,现在我得到了:

在此处输入图像描述

标签: javascriptvuejs2vue-slider-component

解决方案


您应该将选项直接放在<vue-slider>作为属性中。如果将它们添加到数据对象中,它可以是动态的。

<template>
  <div>
    <vue-slider 
      :value='value'
      width='auto'
      :height='6'
      direction='horizontal'
      :dotSize="16"
      eventType='auto'
      :min='5'
      :max='100'
      :interval='5'
      :show='true'
    />
  </div>
</template>

<script>
import vueSlider from 'vue-slider-component'    

export default {
  data: () => ({
    value: 5
  }),
  components: {
    vueSlider
  }
}
</script>

推荐阅读