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>
相关推荐
二哈喇子!4 小时前
BOM模型
开发语言·前端·javascript·bom
二哈喇子!4 小时前
Vue2 监听器 watcher
前端·javascript·vue.js
yanyu-yaya4 小时前
前端面试题
前端·面试·前端框架
二哈喇子!5 小时前
使用NVM下载Node.js管理多版本
前端·npm·node.js
GGGG寄了5 小时前
HTML——文本标签
开发语言·前端·html
2501_944521596 小时前
Flutter for OpenHarmony 微动漫App实战:推荐动漫实现
android·开发语言·前端·javascript·flutter·ecmascript
Amumu121386 小时前
Vue核心(三)
前端·javascript·vue.js
CoCo的编程之路6 小时前
2026 前端效能革命:如何利用智能助手实现“光速”页面构建?深度横评
前端·人工智能·ai编程·comate·智能编程助手·文心快码baiducomate
RFCEO7 小时前
HTML编程 课程五、:HTML5 新增语义化标签
前端·html·html5·跨平台·语义化标签·可生成安卓/ios·html最新版本
CRMEB系统商城7 小时前
CRMEB多商户系统(PHP)- 移动端二开之基本容器组件使用
运维·开发语言·小程序·php