radio.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap">
  5. <view class="uni-title">默认样式</view>
  6. <view>
  7. <label class="radio" style="margin-right: 30rpx;">
  8. <radio value="r1" checked="true" />选中
  9. </label>
  10. <label class="radio">
  11. <radio value="r2" />未选中
  12. </label>
  13. </view>
  14. </view>
  15. <view class="uni-padding-wrap">
  16. <view class="uni-title">不同颜色和尺寸的radio</view>
  17. <view>
  18. <label class="radio" style="margin-right: 30rpx;">
  19. <radio value="r1" checked="true" color="#FFCC33" style="transform:scale(0.7)"/>选中
  20. </label>
  21. <label class="radio">
  22. <radio value="r2" color="#FFCC33" style="transform:scale(0.7)"/>未选中
  23. </label>
  24. </view>
  25. </view>
  26. <view class="uni-title uni-common-mt uni-common-pl">推荐展示样式</view>
  27. <view class="uni-list">
  28. <radio-group @change="radioChange">
  29. <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
  30. <view>
  31. <radio :value="item.value" :checked="index === current" />
  32. </view>
  33. <view>{{item.name}}</view>
  34. </label>
  35. </radio-group>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. title: 'radio 单选框',
  44. items: [{
  45. value: 'USA',
  46. name: '美国'
  47. },
  48. {
  49. value: 'CHN',
  50. name: '中国',
  51. checked: 'true'
  52. },
  53. {
  54. value: 'BRA',
  55. name: '巴西'
  56. },
  57. {
  58. value: 'JPN',
  59. name: '日本'
  60. },
  61. {
  62. value: 'ENG',
  63. name: '英国'
  64. },
  65. {
  66. value: 'FRA',
  67. name: '法国'
  68. },
  69. ],
  70. current: 0
  71. }
  72. },
  73. methods: {
  74. radioChange(evt) {
  75. for (let i = 0; i < this.items.length; i++) {
  76. if (this.items[i].value === evt.detail.value) {
  77. this.current = i;
  78. break;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. .uni-list-cell {
  87. justify-content: flex-start
  88. }
  89. </style>