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

H
hdx 已提交
29
<script>
H
hdx 已提交
30
  type SliderRender = (value : number) => void
H
hdx 已提交
31 32 33 34
  export default {
    data() {
      return {
        title: 'slider 滑块 x 100',
H
hdx 已提交
35
        sliderValue: 50
H
hdx 已提交
36
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
37
    },
H
hdx 已提交
38
    methods: {
H
hdx 已提交
39 40 41
      sliderChange(e : SliderChangeEvent) {
        this.updateSliderValue(e.detail.value)
      },
H
hdx 已提交
42
      sliderChanging(e : SliderChangeEvent) {
H
hdx 已提交
43 44 45 46
        this.updateSliderValue(e.detail.value)
      },
      updateSliderValue(value : Number) {
        // this.sliderValue = value
47

H
hdx 已提交
48 49 50
        // TODO 跳过vue框架,直接修改原生组件
        (this.$refs["slider1"]! as Element[]).forEach((item) => {
          (item.ext['render'] as SliderRender)(value)
51
        });
H
hdx 已提交
52 53
        (this.$refs["slider2"]! as Element[]).forEach((item) => {
          (item.ext['render'] as SliderRender)(value)
54
        });
H
hdx 已提交
55 56
        (this.$refs["slider3"]! as Element[]).forEach((item) => {
          (item.ext['render'] as SliderRender)(value)
57
        });
H
hdx 已提交
58 59
        (this.$refs["slider4"]! as Element[]).forEach((item) => {
          (item.ext['render'] as SliderRender)(value)
60
        });
H
hdx 已提交
61
      }
H
hdx 已提交
62 63
    },
  }
H
hdx 已提交
64 65 66
</script>

<style>
H
hdx 已提交
67 68 69 70 71 72 73
  .page {
    flex: 1;
  }

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

H
hdx 已提交
75 76 77
  .flex-fill {
    flex: 1;
  }
H
hdx 已提交
78

H
hdx 已提交
79
  .slider {
80
    margin: 1px 0.5px;
H
hdx 已提交
81
  }
H
hdx 已提交
82
</style>