switch


开关

示例

  1. <template>
  2. <view>
  3. <view class="box">
  4. <switch
  5. checked="{{ switchValue1 }}"
  6. label="Switch"
  7. c-bind:change="switchChange1"
  8. ></switch>
  9. </view>
  10. <view class="title"> <text> switch value: {{ switchValue1 ? 'true': 'false' }}</text></view>
  11. <view class="box">
  12. <switch
  13. checked="{{ switchValue2 }}"
  14. label="Switch"
  15. c-bind:change="switchChange2"
  16. >
  17. </switch>
  18. </view>
  19. <view class="title"><text> switch value: {{ switchValue2 ? 'true': 'false'}}</text></view>
  20. <view class="box">
  21. <switch
  22. checked="{{ switchValue3 }}"
  23. label="Disabled Switch"
  24. disabled="{{true}}"
  25. ></switch>
  26. </view>
  27. <view class="title"><text> switch value: {{ switchValue3 ? 'true': 'false' }}</text></view>
  28. <view class="box">
  29. <switch
  30. checked="{{ switchValue4 }}"
  31. label="Disabled Switch"
  32. disabled="{{true}}"
  33. ></switch>
  34. </view>
  35. <view class="title"><text> switch value: {{ switchValue4 ? 'true': 'false' }}</text></view>
  36. </view>
  37. </template>
  38. <script>
  39. class Switch {
  40. data = {
  41. switchValue1: false,
  42. switchValue2: true,
  43. switchValue3: true,
  44. switchValue4: false
  45. }
  46. methods = {
  47. switchChange1 (e) {
  48. this.switchValue1 = e.detail.value
  49. },
  50. switchChange2 (e) {
  51. this.switchValue2 = e.detail.value
  52. }
  53. }
  54. }
  55. export default new Switch();
  56. </script>
  57. <style scoped>
  58. .container {
  59. position: absolute;
  60. top: 88cpx;
  61. left: 0;
  62. right: 0;
  63. bottom: 0;
  64. }
  65. .title {
  66. font-size: 38cpx;
  67. font-weight: 400;
  68. margin: 20cpx 0;
  69. padding: 10cpx 30cpx;
  70. background: #eee
  71. }
  72. .radio-value {
  73. font-size: 32cpx;
  74. }
  75. .box {
  76. margin: 0cpx 50cpx;
  77. }
  78. </style>
  79. <script cml-type="json">
  80. {
  81. "base": {}
  82. }
  83. </script>