radio


单选框

示例

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