slider-100.uvue 1.2 KB
Newer Older
H
hdx 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2
  <!-- #ifdef APP -->
H
hdx 已提交
3
  <scroll-view class="page">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
4
  <!-- #endif -->
H
hdx 已提交
5
    <page-head :title="title"></page-head>
H
hdx 已提交
6 7 8
    <view class="grid-view">
      <slider ref="slider" class="slider" v-for="(_, index) in 100" :key="index" @changing="sliderChanging"
        @change="sliderChange" :value="sliderValue" :block-size="20" :show-value="true" />
H
hdx 已提交
9
    </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
10
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
11
  </scroll-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
12
  <!-- #endif -->
H
hdx 已提交
13 14
</template>

H
hdx 已提交
15 16 17 18 19
<script>
  export default {
    data() {
      return {
        title: 'slider 滑块 x 100',
H
hdx 已提交
20
        sliderValue: 50
H
hdx 已提交
21
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
22
    },
H
hdx 已提交
23
    methods: {
H
hdx 已提交
24
      sliderChange(e : UniSliderChangeEvent) {
H
hdx 已提交
25 26
        this.updateSliderValue(e.detail.value)
      },
H
hdx 已提交
27
      sliderChanging(e : UniSliderChangeEvent) {
H
hdx 已提交
28 29
        this.updateSliderValue(e.detail.value)
      },
H
hdx 已提交
30
      updateSliderValue(value : number) {
H
hdx 已提交
31
        // TODO 跳过vue框架,直接修改原生组件
H
hdx 已提交
32
        (this.$refs["slider"] as UniSliderElement[]).forEach((item) => {
H
hdx 已提交
33 34
          item.value = value
        });
H
hdx 已提交
35
      }
H
hdx 已提交
36 37
    },
  }
H
hdx 已提交
38 39 40
</script>

<style>
H
hdx 已提交
41 42 43 44
  .page {
    flex: 1;
  }

H
hdx 已提交
45
  .grid-view {
H
hdx 已提交
46
    flex-direction: row;
H
hdx 已提交
47
    flex-wrap: wrap;
H
hdx 已提交
48
  }
H
hdx 已提交
49

H
hdx 已提交
50
  .slider {
H
hdx 已提交
51 52 53
    width: 25%;
    margin-top: 1px;
    margin-bottom: 1px;
H
hdx 已提交
54
  }
55
</style>