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

<script>
  export default {
    data() {
      return {
        title: 'slider 滑块 x 100',
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
21 22
        sliderValue: 50,
        safeAreaInsetsBottom: 0
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24
      }
    },
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
25 26 27
    onReady() {
      this.safeAreaInsetsBottom = uni.getWindowInfo().safeAreaInsets.bottom;
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
28 29 30 31 32 33 34
    methods: {
      sliderChange(e : UniSliderChangeEvent) {
        this.updateSliderValue(e.detail.value)
      },
      sliderChanging(e : UniSliderChangeEvent) {
        this.updateSliderValue(e.detail.value)
      },
35 36 37 38 39 40 41 42 43 44 45
      updateSliderValue(value : number) {
        // #ifndef MP
        // TODO 跳过vue框架,直接修改原生组件
        (this.$refs["slider"] as UniSliderElement[]).forEach((item) => {
          item.value = value
        });
        // #endif

        // #ifdef MP
        this.sliderValue = value
        // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      }
    },
  }
</script>

<style>
  .page {
    flex: 1;
  }

  .grid-view {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .slider {
    width: 25%;
63 64 65
    margin-top: 1px;
    margin-left:0;
    margin-right: 0;
DCloud-WZF's avatar
DCloud-WZF 已提交
66 67
    margin-bottom: 1px;
  }
68
</style>