c-radio-group


单选框列表

示例

  1. <template>
  2. <page title="radio group演示">
  3. <view class="box">
  4. <c-radio-group
  5. option="{{ radioGroupOption1 }}"
  6. c-bind:groupchange="groupChangeHandler1"
  7. >
  8. </c-radio-group>
  9. </view>
  10. <view class="title">
  11. <text>selected value: {{ radioSelect1 ? 'true' : 'false'}}</text>
  12. </view>
  13. <view class="box">
  14. <c-radio-group
  15. option="{{ radioGroupOption2 }}"
  16. position="right"
  17. c-bind:groupchange="groupChangeHandler2"
  18. >
  19. </c-radio-group>
  20. </view>
  21. <view class="title">
  22. <text>selected value: {{ radioSelect2 ? 'true' : 'false' }}</text>
  23. </view>
  24. <view class="box">
  25. <c-radio-group
  26. option="{{ radioGroupOption3 }}"
  27. horizontal="{{ true }}"
  28. c-bind:groupchange="groupChangeHandler3"
  29. >
  30. </c-radio-group>
  31. </view>
  32. <view class="title">
  33. <text>selected value: {{ radioSelect3 ? 'true' : 'false' }}</text>
  34. </view>
  35. </page>
  36. </template>
  37. <script>
  38. class CRadio {
  39. data = {
  40. radioGroupOption1: [{
  41. checked: false,
  42. label: 'Option1',
  43. }, {
  44. checked: false,
  45. label: 'Option2'
  46. }, {
  47. checked: false,
  48. label: 'Option3',
  49. disabled: true
  50. }],
  51. radioSelect1: '',
  52. radioGroupOption2: [{
  53. checked: true,
  54. label: 'Option1',
  55. }, {
  56. checked: false,
  57. label: 'Option2'
  58. }, {
  59. checked: false,
  60. label: 'Option3',
  61. disabled: true
  62. }],
  63. radioSelect2: 'Option1',
  64. radioGroupOption3: [{
  65. checked: true,
  66. label: 'Option1',
  67. }, {
  68. checked: false,
  69. label: 'Option2'
  70. }, {
  71. checked: false,
  72. label: 'Option3',
  73. disabled: true
  74. }],
  75. radioSelect3: 'Option1',
  76. }
  77. computed = {
  78. }
  79. watch = {
  80. }
  81. methods = {
  82. groupChangeHandler1 (e) {
  83. this.radioSelect1 = this.radioGroupOption1[e.detail.index].label
  84. },
  85. groupChangeHandler2 (e) {
  86. this.radioSelect2 = this.radioGroupOption2[e.detail.index].label
  87. },
  88. groupChangeHandler3 (e) {
  89. this.radioSelect3 = this.radioGroupOption3[e.detail.index].label
  90. },
  91. }
  92. beforeCreate() {
  93. }
  94. created() {
  95. }
  96. beforeMount() {
  97. }
  98. mounted() {
  99. }
  100. beforeDestroy() {
  101. }
  102. destroyed() {
  103. }
  104. }
  105. export default new CRadio();
  106. </script>
  107. <style scoped>
  108. .container {
  109. position: absolute;
  110. top: 88cpx;
  111. left: 0;
  112. right: 0;
  113. bottom: 0;
  114. }
  115. .title {
  116. font-size: 38cpx;
  117. font-weight: 400;
  118. margin: 20cpx 0;
  119. padding: 10cpx 30cpx;
  120. background: #eee
  121. }
  122. .radio-value {
  123. font-size: 32cpx;
  124. }
  125. .box {
  126. margin: 0 50cpx;
  127. }
  128. </style>
  129. <script cml-type="json">
  130. {
  131. "base": {
  132. "usingComponents": {
  133. "c-radio-group": "cml-ui/components/c-radio-group/c-radio-group"
  134. }
  135. }
  136. }
  137. </script>