slider-100.uvue 2.2 KB
Newer Older
H
hdx 已提交
1
<template>
H
hdx 已提交
2 3 4 5
  <scroll-view class="page">
    <page-head :title="title"></page-head>
    <view class="flex-row">
      <view class="flex-fill">
6
        <slider ref="slider1" v-for="(_, index1) in 25" :key="index1" class="slider" @changing="sliderChanging"
H
hdx 已提交
7
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
H
hdx 已提交
8 9
      </view>
      <view class="flex-fill">
10
        <slider ref="slider2" v-for="(_, index2) in 25" :key="index2" class="slider" @changing="sliderChanging"
H
hdx 已提交
11
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
H
hdx 已提交
12 13
      </view>
      <view class="flex-fill">
14
        <slider ref="slider3" v-for="(_, index3) in 25" :key="index3" class="slider" @changing="sliderChanging"
H
hdx 已提交
15
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
H
hdx 已提交
16 17
      </view>
      <view class="flex-fill">
18
        <slider ref="slider4" v-for="(_, index4) in 25" :key="index4" class="slider" @changing="sliderChanging"
H
hdx 已提交
19
          @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
H
hdx 已提交
20 21
      </view>
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
22
  </scroll-view>
H
hdx 已提交
23 24
</template>

H
hdx 已提交
25 26 27 28 29
<script>
  export default {
    data() {
      return {
        title: 'slider 滑块 x 100',
H
hdx 已提交
30
        sliderValue: 50
H
hdx 已提交
31
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
32
    },
H
hdx 已提交
33
    methods: {
H
hdx 已提交
34
      sliderChange(e : UniSliderChangeEvent) {
H
hdx 已提交
35 36
        this.updateSliderValue(e.detail.value)
      },
H
hdx 已提交
37
      sliderChanging(e : UniSliderChangeEvent) {
H
hdx 已提交
38 39
        this.updateSliderValue(e.detail.value)
      },
H
hdx 已提交
40
      updateSliderValue(value : number) {
H
hdx 已提交
41
        // this.sliderValue = value
42

H
hdx 已提交
43
        // TODO 跳过vue框架,直接修改原生组件
44
        (this.$refs["slider1"] as UniSliderElement[]).forEach((item) => {
H
hdx 已提交
45 46
          item.value = value
        });
47
        (this.$refs["slider2"] as UniSliderElement[]).forEach((item) => {
H
hdx 已提交
48 49
          item.value = value
        });
50
        (this.$refs["slider3"] as UniSliderElement[]).forEach((item) => {
H
hdx 已提交
51 52
          item.value = value
        });
53
        (this.$refs["slider4"] as UniSliderElement[]).forEach((item) => {
H
hdx 已提交
54 55
          item.value = value
        });
H
hdx 已提交
56
      }
H
hdx 已提交
57 58
    },
  }
H
hdx 已提交
59 60 61
</script>

<style>
H
hdx 已提交
62 63 64 65 66 67 68
  .page {
    flex: 1;
  }

  .flex-row {
    flex-direction: row;
  }
H
hdx 已提交
69

H
hdx 已提交
70 71 72
  .flex-fill {
    flex: 1;
  }
H
hdx 已提交
73

H
hdx 已提交
74
  .slider {
75
    margin: 1px 0.5px;
H
hdx 已提交
76
  }
77
</style>