switch.uvue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view>
  3. <view class="uni-padding-wrap uni-common-mt">
  4. <view class="uni-title">默认样式</view>
  5. <view class="flex-row">
  6. <switch class="switch-checked" :checked="checked" @change="switch1Change" />
  7. <switch @change="switch2Change" />
  8. </view>
  9. <view class="uni-title">暗黑样式</view>
  10. <view class="flex-row">
  11. <switch id="darkChecked" background-color="#1f1f1f" activeBackgroundColor="#007aff" foreColor="#f0f0f0"
  12. activeForeColor="#ffffff" :checked="checked" />
  13. <switch id="dark" background-color="#1f1f1f" activeBackgroundColor="#007aff" foreColor="#f0f0f0"
  14. activeForeColor="#ffffff" />
  15. </view>
  16. <view class="uni-title">禁用样式</view>
  17. <view class="flex-row">
  18. <switch class="switch-checked" :checked="checked" :disabled="true" />
  19. <switch :disabled="true" />
  20. </view>
  21. <view class="uni-title">不同颜色和尺寸的switch</view>
  22. <view class="flex-row">
  23. <switch class="switch-color-checked" :color="color" style="transform:scale(0.7)" :checked="true" />
  24. <switch class="switch-color" :color="color" style="transform:scale(0.7)" />
  25. </view>
  26. <view class="uni-title">推荐展示样式</view>
  27. </view>
  28. <view class="uni-list">
  29. <view class="uni-list-cell uni-list-cell-padding">
  30. <view class="uni-list-cell-db">开启中</view>
  31. <switch :checked="true" />
  32. </view>
  33. <view class="uni-list-cell uni-list-cell-padding">
  34. <view class="uni-list-cell-db">关闭</view>
  35. <switch />
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script lang="uts">
  41. export default {
  42. data() {
  43. return {
  44. title: 'switch 开关',
  45. checked: true,
  46. color: '#FFCC33',
  47. clickCheckedValue: true,
  48. testVerifyEvent: false,
  49. }
  50. },
  51. methods: {
  52. switch1Change: function (e : UniSwitchChangeEvent) {
  53. this.clickCheckedValue = e.detail.value
  54. console.log('switch1 发生 change 事件,携带值为', e.detail.value)
  55. // 仅测试
  56. this.testVerifyEvent = (e.type == 'change' && (e.target?.tagName ?? '') == "SWITCH")
  57. },
  58. switch2Change: function (e : UniSwitchChangeEvent) {
  59. console.log('switch2 发生 change 事件,携带值为', e.detail.value)
  60. }
  61. }
  62. }
  63. </script>
  64. <style>
  65. .flex-row {
  66. flex-direction: row;
  67. }
  68. </style>