uniapp實(shí)現(xiàn)單選框的示例代碼
采用uniapp-vue3實(shí)現(xiàn)的一款單選框組件,提供絲滑的動(dòng)畫選中效果,支持不同主題配置,適配web、H5、微信小程序(其他平臺(tái)小程序未測(cè)試過(guò),可自行嘗試)
可到插件市場(chǎng)下載嘗試: https://ext.dcloud.net.cn/plugin?id=16821
使用示例

示例代碼
<template>
<view>
<view class="light" style="background-color: white">
<wo-radio v-model:options="state.items" v-model:defaultValue="state.default" @on-change="changeEvent">
</wo-radio>
</view>
<view class="light">
<wo-radio v-model:options="state.items" v-model:defaultValue="state.default" v-model:styleObj="state.theme.light" v-slot="slotProps" @on-change="changeEvent">
<view style="display: flex;">
<view>{{ slotProps.data.name }}</view>
<view class="tag">{{ slotProps.data.tag }}</view>
</view>
</wo-radio>
</view>
<view class="dark">
<wo-radio v-model:options="state.items" v-model:defaultValue="state.default" v-model:styleObj="state.theme.dark" v-slot="slotProps" @on-change="changeEvent">
<view style="display: flex;">
<view>{{ slotProps.data.name }}</view>
<view class="tag">{{ slotProps.data.tag }}</view>
</view>
</wo-radio>
</view>
</view>
</template>
<script setup lang="ts">
import { reactive } from 'vue';
const state = reactive({
items: [{
value: '1',
name: '蘋果味',
tag: '飲料'
},
{
value: '2',
name: '香蕉味',
tag: '酒水'
},
{
value: '3',
name: '火龍果味',
tag: '飲料'
},
{
value: '4',
name: '西瓜味',
tag: '飲料'
},
{
value: '5',
name: '哈密瓜味',
tag: '酒水'
},
{
value: '6',
name: '榴蓮味',
tag: '酒水'
}],
default: '2',
theme: {
light: {
primary: 'blue',
unselectedRadioBg: '#eaeaea',
selectedBg: 'hsla(0,0%,100%,0.5)',
height: 20
},
dark: {
primary: 'blue',
unselectedRadioBg: 'hsl(223,90%,30%)',
selectedBg: 'hsla(223,90%,30%,0.5)',
height: 20
}
},
height: 12
});
const changeEvent = (el) => {
console.log('點(diǎn)擊:', 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;
}
.tag {
background-color: #1BA035;
color: white;
font-size: 10px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
padding: 0 4px;
margin-left: 5px;
}
</style>到此這篇關(guān)于uniapp實(shí)現(xiàn)單選框的文章就介紹到這了,更多相關(guān)uniapp單選框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript獲取上傳進(jìn)度的幾種方式實(shí)現(xiàn)
進(jìn)度條的應(yīng)用是為了顯示的告訴用戶文件上傳了多少,本文主要介紹了JavaScript獲取上傳進(jìn)度的幾種方式,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-08-08
JavaScript簡(jiǎn)單實(shí)現(xiàn)合并兩個(gè)Json對(duì)象的方法示例
這篇文章主要介紹了JavaScript簡(jiǎn)單實(shí)現(xiàn)合并兩個(gè)Json對(duì)象的方法,結(jié)合實(shí)例形式分析了json對(duì)象的遍歷、添加實(shí)現(xiàn)合并的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
一個(gè)關(guān)于javascript匿名函數(shù)的問(wèn)題分析
一個(gè)關(guān)于javascript匿名函數(shù)的問(wèn)題分析,學(xué)習(xí)js的朋友可以參考下2012-03-03
10個(gè)很少使用的JavaScript?Console方法分享
你一定聽說(shuō)過(guò)?console.log()?,而且可能一直在使用它,在本文中,我們將探討一些最有用的控制臺(tái)方法,以及它們?cè)跀?shù)據(jù)可視化、調(diào)試等方面的用途,感興趣的小伙伴可以學(xué)習(xí)一下2023-09-09
webpack配置文件外置的兩種實(shí)現(xiàn)方式
webpack配置環(huán)境變量文件,是根據(jù)打包命令尋找對(duì)應(yīng)的環(huán)境變量文件,從而獲取接口地址,本文就來(lái)介紹一下webpack配置文件外置的兩種實(shí)現(xiàn)方式,感興趣的可以了解一下2023-12-12
JS實(shí)現(xiàn)的緩沖運(yùn)動(dòng)效果示例
這篇文章主要介紹了JS實(shí)現(xiàn)的緩沖運(yùn)動(dòng)效果,涉及JavaScript數(shù)值運(yùn)算與時(shí)間函數(shù)相關(guān)使用技巧,需要的朋友可以參考下2018-04-04

