uniapp实现---单选题按钮

目录

一、实现思路

二、实现步骤

①view部分展示

[②JavaScript 内容](#②JavaScript 内容)

③css中样式展示

三、效果展示


一、实现思路

使用样式布局控制单选框的位置,这里使用的是原生态uniapp,并没有使用组件。

二、实现步骤

①view部分展示

html 复制代码
<template>
	<view style="padding-bottom: 100px;">
		<f-navbar title="参与评价" navbarType="3"></f-navbar>
		<view style="position: absolute;top: 50px; margin-top: 48rpx;">
			<view style="margin: 48rpx 32rpx;">
				<view class="titlea">您对学校食堂的菜品口味满意吗?</view>
				<view class="radio-group">
					<radio-group @change="radioChange">
						<view class="radio-row">
							<label class="radio-label">
								<radio value="1" class="custom-radio" color="#CCCCCC"/>不满意
							</label>
							<label class="radio-label">
								<radio value="2" class="custom-radio" color="#CCCCCC"/>一般
							</label>
						</view>
						<view class="radio-row">
							<label class="radio-label">
								<radio value="3" class="custom-radio" color="#CCCCCC"/>满意
							</label>
							<label class="radio-label">
								<radio value="4" class="custom-radio" color="#CCCCCC"/>非常满意
							</label>
						</view>
					</radio-group>
				</view>
			</view>

			<view style="margin: 48rpx 32rpx;">
				<view>您对食堂的餐具清洁度满意吗?</view>
				<view class="radio-group">
					<radio-group @change="radioChange">
						<view class="radio-row">
							<label class="radio-label">
								<radio value="1" class="custom-radio" color="#CCCCCC"/>不满意
							</label>
							<label class="radio-label">
								<radio value="2" class="custom-radio" color="#CCCCCC"/>一般
							</label>
						</view>
						<view class="radio-row">
							<label class="radio-label">
								<radio value="3" class="custom-radio" color="#CCCCCC"/>满意
							</label>
							<label class="radio-label">
								<radio value="4" class="custom-radio" color="#CCCCCC"/>非常满意
							</label>
						</view>
					</radio-group>
				</view>
			</view>
		</view>
	</view>

</template>

②JavaScript 内容

javascript 复制代码
<script>
	export default {
		data() {
			return {
				fromdeta: {
					age: '', // 选中的年级
				},
			};

		},

		methods: {
			radioChange(n) {
				console.log('radioChange', n);
			}
		}
	}
</script>

③css中样式展示

css 复制代码
<style scoped lang="scss">
	.radio-group {
		margin: 16rpx;
		display: flex;
		flex-direction: column;

	}

	.radio-row {
		display: flex;
	}

	.radio-label {
		display: flex;
		align-items: center;
		margin-bottom: 24rpx;
		width: 50%;
		font-size: 28rpx;
		color: #1A1A1A;
	}

	/* 调整单选框与文字之间的距离 */
	.custom-radio {
		margin-right: 10rpx;
		transform: scale(0.7)
	}

	.titlea {
		font-size: 32rpx;
		color: #1A1A1A;
		letter-spacing: 2rpx;
	}
</style>

三、效果展示

可以单选,选中的颜色,可以根据自己的需要调节

相关推荐
小小小米粒8 分钟前
Maven Tools
java
xkxnq12 分钟前
第五阶段:Vue3核心深度深挖(第74天)(Vue3计算属性进阶)
前端·javascript·vue.js
三小河18 分钟前
Agent Skill与Rules的区别——以Cursor为例
前端·javascript·后端
kali-Myon22 分钟前
2025春秋杯网络安全联赛冬季赛-day1
java·sql·安全·web安全·ai·php·web
Hilaku25 分钟前
不要在简历上写精通 Vue3?来自面试官的真实劝退
前端·javascript·vue.js
我是咸鱼不闲呀26 分钟前
力扣Hot100系列20(Java)——[动态规划]总结(下)( 单词拆分,最大递增子序列,乘积最大子数组 ,分割等和子集,最长有效括号)
java·leetcode·动态规划
三小河31 分钟前
前端视角详解 Agent Skill
前端·javascript·后端
清水白石00835 分钟前
深入解析 LRU 缓存:从 `@lru_cache` 到手动实现的完整指南
java·python·spring·缓存
Aniugel44 分钟前
单点登录(SSO)系统
前端
颜酱1 小时前
二叉树遍历思维实战
javascript·后端·算法