uniapp实现单选框卡片选择器,支持微信小程序、H5等多端

采用uniapp-vue3实现的一款单选框卡片选择器,纯CSS实现样式和交互,提供丝滑的动画选中效果,支持不同主题配置,适配多端

可到插件市场下载尝试: https://ext.dcloud.net.cn/plugin?id=16901

  • 使用示例
  • 示例代码
javascript 复制代码
<template>
	<view>
		<view class="light">
			<wo-card-radio v-model:options="state.items" v-model:defaultValue="state.default" @on-change="changeEvent"></wo-card-radio>
		</view>
		<view class="dark">
			<wo-card-radio v-model:options="state.items" v-model:defaultValue="state.default" v-model:styleObj="state.theme.dark" @on-change="changeEvent"></wo-card-radio>
		</view>
	</view>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
const state = reactive({
	items: [
		{
			value: 'test',
			label: '中国农业银行',
			cardLinearColor: 'linear-gradient(45deg, #89c888, #1BA035)'
		},
		{
			value: 'test2',
			label: '中国工商银行',
			cardLinearColor: 'linear-gradient(45deg, #ff8c75, #FF4A3B)'
		},
		{
			value: 'test3',
			label: '中国建设银行',
			cardLinearColor: 'linear-gradient(45deg, #748DFB, #3859E8)'
		},
		{
			value: 'test2',
			label: '中国华夏银行',
			cardLinearColor: 'linear-gradient(45deg, #616161, #484848)'
		},
	],
	default: 'test3',
	theme: {
			light: {
				primary: 'blue',
				unselectedRadioBg: '#eaeaea',
				selectedBg: 'hsla(0,0%,100%,0.5)',
			},
			dark: {
				primary: 'blue',
				unselectedRadioBg: 'hsl(223,90%,30%)',
				selectedBg: 'hsla(223,90%,30%,0.5)'
			}
	}
});
const changeEvent = (el) => {
	console.log('点击:', el);
}
</script>

<style lang="scss" scoped>
	.light {
		border-radius: 10px;
		padding: 20rpx;
		font-size: 24rpx;
		background-color: hsl(223,90%,90%);
		margin: 20px;
		height: 300px;
		overflow: auto;
	}
	.dark {
		border-radius: 10px;
		padding: 20rpx;
		font-size: 24rpx;
		background-color: hsl(223,90%,10%);
		color: white;
		margin: 20px;
		height: 300px;
		overflow: auto;
	}
</style>
相关推荐
RoyLin6 分钟前
TypeScript设计模式:桥接模式
前端·后端·typescript
火星开发者8 分钟前
Vue中实现Word、Excel、PDF预览的详细步骤
前端
brzhang14 分钟前
干翻 Docker?WebAssembly 3.0 的野心,远不止浏览器,来一起看看吧
前端·后端·架构
lecepin1 小时前
AI Coding 资讯 2025-09-17
前端·javascript·面试
IT_陈寒1 小时前
React 18实战:7个被低估的Hooks技巧让你的开发效率提升50%
前端·人工智能·后端
树上有只程序猿2 小时前
终于有人把数据库讲明白了
前端
猩兵哥哥2 小时前
前端面向对象设计原则运用 - 策略模式
前端·javascript·vue.js
司宸2 小时前
Prompt设计实战指南:三大模板与进阶技巧
前端
RoyLin2 小时前
TypeScript设计模式:抽象工厂模式
前端·后端·typescript
华仔啊2 小时前
Vue3+CSS 实现的 3D 卡片动画,让你的网页瞬间高大上
前端·css