index.uvue 2.3 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
<template>
  <!-- #ifdef APP -->
  <scroll-view class="page">
  <!-- #endif -->
    <page-head :title="title"></page-head>
    <view class="flex-row">
      <view class="flex-fill">
        <slider ref="slider1" v-for="(_, index1) in 25" :key="index1" class="slider" @changing="sliderChanging"
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
      </view>
      <view class="flex-fill">
        <slider ref="slider2" v-for="(_, index2) in 25" :key="index2" class="slider" @changing="sliderChanging"
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
      </view>
      <view class="flex-fill">
        <slider ref="slider3" v-for="(_, index3) in 25" :key="index3" class="slider" @changing="sliderChanging"
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
      </view>
      <view class="flex-fill">
        <slider ref="slider4" v-for="(_, index4) in 25" :key="index4" class="slider" @changing="sliderChanging"
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script>
  export default {
    data() {
      return {
        title: 'slider 滑块 x 100',
        sliderValue: 50
      }
    },
    methods: {
      sliderChange(e : SliderChangeEvent) {
        this.updateSliderValue(e.detail.value)
      },
      sliderChanging(e : SliderChangeEvent) {
        this.updateSliderValue(e.detail.value)
      },
      updateSliderValue(value : number) {
        // this.sliderValue = value

        // TODO 跳过vue框架,直接修改原生组件
        (this.$refs["slider1"] as UniSliderElement[]).forEach((item) => {
          item.value = value
        });
        (this.$refs["slider2"] as UniSliderElement[]).forEach((item) => {
          item.value = value
        });
        (this.$refs["slider3"] as UniSliderElement[]).forEach((item) => {
          item.value = value
        });
        (this.$refs["slider4"] as UniSliderElement[]).forEach((item) => {
          item.value = value
        });
      }
    },
  }
</script>

<style>
  .page {
    flex: 1;
  }

  .flex-row {
    flex-direction: row;
  }

  .flex-fill {
    flex: 1;
  }

  .slider {
    margin: 1px 0.5px;
  }
</style>