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

<style>
    .uni-list-cell {
        justify-content: flex-start
    }
</style>