number-box.nvue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view class="page">
  3. <uni-card :is-shadow="false" is-full>
  4. <text class="uni-h6">数字输入框组件多用于购物车加减商品等场景</text>
  5. </uni-card>
  6. <uni-section title="基本用法" type="line" padding>
  7. <uni-number-box @change="changeValue" />
  8. </uni-section>
  9. <uni-section :title="'使用v-model : '+ vModelValue" subTitle="使用 v-model 显示默认值" type="line" padding>
  10. <uni-number-box v-model = "vModelValue" @blur="blur" @focus="focus" @change="changeValue" />
  11. </uni-section>
  12. <uni-section title="设置最小值和最大值" subTitle="使用 min \ max 属性设置最大最小值" type="line" padding>
  13. <uni-number-box :min="2" :max="9" :value="555" />
  14. </uni-section>
  15. <uni-section title="设置步长(步长0.1)" subTitle="使用 step 属性设置步长" type="line" padding>
  16. <uni-number-box :value="1.1" :step="0.1" />
  17. </uni-section>
  18. <uni-section title="自定义背景" type="line" subTitle="使用 background 属性设置自定义背景色" padding>
  19. <uni-number-box :value="50" background="#2979FF" color="#fff" />
  20. </uni-section>
  21. <uni-section title="禁用状态" subTitle="使用 disabled 属性设置组件禁用" type="line" padding>
  22. <uni-number-box :disabled="true" />
  23. </uni-section>
  24. <uni-section :title="'获取输入的值 : '+ numberValue" type="line" padding>
  25. <uni-number-box :value="numberValue" @change="change" />
  26. </uni-section>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. components: {},
  32. data() {
  33. return {
  34. numberValue: 0,
  35. vModelValue: 3
  36. }
  37. },
  38. methods: {
  39. change(value) {
  40. this.numberValue = value
  41. },
  42. changeValue(value) {
  43. console.log('返回数值:', value);
  44. },
  45. blur(e) {
  46. console.log('-------blur:', e);
  47. },
  48. focus(e) {
  49. console.log('-------focus:', e);
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss">
  55. </style>