radio.uvue 3.8 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
Y
init  
yurj26 已提交
5
    <view>
DCloud-WZF's avatar
DCloud-WZF 已提交
6 7 8 9
      <page-head :title="title"></page-head>
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 默认样式 </text>
Y
init  
yurj26 已提交
10
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
        <radio-group
          class="uni-flex uni-row radio-group"
          @change="testChange"
          style="flex-wrap: wrap"
        >
          <radio
            value="r"
            :checked="checked"
            :color="color"
            style="margin-right: 30rpx"
            class="radio r"
            >选中
          </radio>
          <radio value="r1" style="margin-right: 30rpx" class="radio r1">{{
            text
          }}</radio>
          <radio value="r2" :disabled="disabled" class="radio r2">禁用</radio>
          <radio value="r3" class="radio r3" style="margin-top: 20rpx">{{
            wrapText
          }}</radio>
        </radio-group>
      </view>
Y
yurj26 已提交
33

DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 不同颜色和尺寸的radio </text>
Y
init  
yurj26 已提交
37
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        <radio-group class="uni-flex uni-row radio-group">
          <radio
            value="r1"
            :checked="true"
            color="#FFCC33"
            style="transform: scale(0.7); margin-right: 30rpx"
            class="radio"
            >选中
          </radio>
          <radio
            value="r2"
            color="#FFCC33"
            style="transform: scale(0.7)"
            class="radio"
            >未选中</radio
          >
        </radio-group>
      </view>
Y
yurj26 已提交
56

DCloud-WZF's avatar
DCloud-WZF 已提交
57 58 59
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 推荐展示样式 </text>
Y
init  
yurj26 已提交
60
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
      </view>
      <view class="uni-list uni-common-pl">
        <radio-group @change="radioChange" class="radio-group">
          <radio
            class="uni-list-cell uni-list-cell-pd radio"
            v-for="(item, index) in items"
            :key="item.value"
            :class="index < items.length - 1 ? 'uni-list-cell-line' : ''"
            :value="item.value"
            :checked="index === current"
          >
            {{ item.name }}
          </radio>
        </radio-group>
      </view>
Y
init  
yurj26 已提交
76
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
77 78 79
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
init  
yurj26 已提交
80 81
</template>
<script lang="ts">
DCloud-WZF's avatar
DCloud-WZF 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
type ItemType = {
  value: string
  name: string
}
export default {
  data() {
    return {
      title: 'radio 单选框',
      items: [
        {
          value: 'CHN',
          name: '中国',
        },
        {
          value: 'USA',
          name: '美国',
        },
Y
yurj26 已提交
99

DCloud-WZF's avatar
DCloud-WZF 已提交
100 101 102
        {
          value: 'BRA',
          name: '巴西',
Y
init  
yurj26 已提交
103
        },
DCloud-WZF's avatar
DCloud-WZF 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        {
          value: 'JPN',
          name: '日本',
        },
        {
          value: 'ENG',
          name: '英国',
        },
        {
          value: 'FRA',
          name: '法国',
        },
      ] as ItemType[],
      current: 0,

      value: '',
      text: '未选中',
      wrapText: 'uni-app x,终极跨平台方案\nuts,大一统语言',
      disabled: true,
      checked: true,
      color: '#007aff',
Y
init  
yurj26 已提交
125
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  },
  methods: {
    radioChange(e: RadioGroupChangeEvent) {
      const selected = this.items.find((item): boolean => {
        return item.value == e.detail.value
      })
      uni.showToast({
        icon: 'none',
        title: '当前选中:' + selected?.name,
      })
    },
    testChange(e: RadioGroupChangeEvent) {
      this.value = e.detail.value
    },
  },
}
Y
init  
yurj26 已提交
142 143 144
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
145 146 147 148
.uni-list-cell {
  justify-content: flex-start;
}
</style>