Ruler 刻度尺

Scan me!

可滑动刻度尺2.2.0+

引入

  1. import { Ruler } from 'mand-mobile'
  2. Vue.component(Ruler.name, Ruler)

代码演示

基本

请在移动设备中扫码预览

Ruler 刻度尺 - 图2

  1. <template>
  2. <div class="md-example-child md-example-child-single-component">
  3. <p>当前值:{{ value }}</p>
  4. <div class="container">
  5. <md-ruler
  6. :scope="scope"
  7. :step="100"
  8. :unit="10"
  9. v-model="value"
  10. ></md-ruler>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import {Ruler} from 'mand-mobile'
  16. export default {
  17. name: 'ruler-demo-0',
  18. components: {
  19. [Ruler.name]: Ruler,
  20. },
  21. data() {
  22. return {
  23. value: 1000,
  24. scope: [1000, 2000],
  25. }
  26. },
  27. }
  28. </script>
  29. <style lang="stylus" scoped>
  30. .md-example-child-single-component
  31. .container
  32. margin 0 auto
  33. width 640px
  34. </style>
  35.  

触发 Change to 1500

只在滚动停止时有效
请在移动设备中扫码预览

Ruler 刻度尺 - 图3

        <template>
  <div class="md-example-child md-example-child-single-component">
    <p>当前值:{{ value }}</p>
    <div class="container">
      <md-ruler
        :scope="scope"
        :step="100"
        :unit="10"
        :max="2000"
        :min="1000"
        v-model="value"
      ></md-ruler>
    </div>
  </div>
</template>

<script>
import {Ruler} from 'mand-mobile'

export default {
  name: 'ruler-demo',
  components: {
    [Ruler.name]: Ruler,
  },
  data() {
    return {
      value: 1300,
      scope: [1000, 2000],
    }
  },
  mounted() {
    window.triggerRuler2 = () => {
      this.value = 1500
    }
  },
}

</script>

<style lang="stylus" scoped>
  .md-example-child-single-component
    .container
      margin 0 auto
      width 640px
</style>

      

自定义step展示位置

请在移动设备中扫码预览

Ruler 刻度尺 - 图4

        <template>
  <div class="md-example-child md-example-child-single-component">
    <p>当前值:{{ value }}</p>
    <div class="container">
      <md-ruler
        v-model="value"
        step-text-position="bottom"
        :scope="scope"
        :step="100"
        :unit="10"
      ></md-ruler>
    </div>
  </div>
</template>

<script>
import {Ruler} from 'mand-mobile'

export default {
  name: 'ruler-demo',
  components: {
    [Ruler.name]: Ruler,
  },
  data() {
    return {
      value: 1300,
      scope: [1000, 2000],
    }
  },
}

</script>

<style lang="stylus" scoped>
  .md-example-child-single-component
    .container
      margin 0 auto
      width 640px
</style>

      

最大1800,最小1200

请在移动设备中扫码预览

Ruler 刻度尺 - 图5

        <template>
  <div class="md-example-child md-example-child-single-component">
    <p>当前值:{{ value }}</p>
    <div class="container">
      <md-ruler
        :scope="scope"
        :step="100"
        :unit="10"
        :max="1800"
        :min="1200"
        v-model="value"
      ></md-ruler>
    </div>
  </div>
</template>

<script>
import {Ruler} from 'mand-mobile'

export default {
  name: 'ruler-demo-1',
  components: {
    [Ruler.name]: Ruler,
  },
  data() {
    return {
      value: 1305,
      scope: [1000, 2000],
    }
  },
}

</script>

<style lang="stylus" scoped>
  .md-example-child-single-component
    .container
      margin 0 auto
      width 640px
</style>

      

自定义step展示文案

请在移动设备中扫码预览

Ruler 刻度尺 - 图6

        <template>
  <div class="md-example-child md-example-child-single-component">
    <p>当前值:{{ value }}</p>
    <div class="container">
      <md-ruler
        v-model="value"
        :scope="scope"
        :step="100"
        :unit="10"
        :step-text-render="stepTextRender"
      ></md-ruler>
    </div>
  </div>
</template>

<script>
import {Ruler} from 'mand-mobile'

export default {
  name: 'ruler-demo',
  components: {
    [Ruler.name]: Ruler,
  },
  data() {
    return {
      value: 1300,
      scope: [1000, 2000],
    }
  },
  methods: {
    stepTextRender(step) {
      return step + 'cm'
    },
  },
}

</script>

<style lang="stylus" scoped>
  .md-example-child-single-component
    .container
      margin 0 auto
      width 640px
</style>

      

API

Ruler Props

属性说明类型默认值备注
v-model双向绑定的值Number0-
scope刻度尺范围Number[][0, 100]-
step刻度尺每一大格步数Number10-
unit刻度尺每一小格步数Number1-
min最小可滑动位置Number0-
max最大可滑动位置Number100-
stepTextPosition2.2.1+Step标志位置String'top'可选'top', 'bottom'
stepTextRender2.2.1+自定义step文案Functionnoop自定义函数应该返回字符串

Ruler Events

@change(currentValue)

值发生变化事件