uniapp實(shí)現(xiàn)單選框的示例代碼
采用uniapp-vue3實(shí)現(xiàn)的一款單選框組件,提供絲滑的動(dòng)畫(huà)選中效果,支持不同主題配置,適配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: '蘋(píng)果味', 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 Scoping and Hoisting 翻譯
希望這篇文章能夠給JavaScript程序員最容易困惑的部分一些啟示。我盡力寫(xiě)的全面,以免引起更多的困惑。如果我寫(xiě)錯(cuò)了或是漏掉了某些重要的東西,請(qǐng)一定讓我知道2012-07-07JavaScript匿名函數(shù)之模仿塊級(jí)作用域
這篇文章主要介紹了JavaScript匿名函數(shù)之模仿塊級(jí)作用域的相關(guān)資料,需要的朋友可以參考下2015-12-12

JS+CSS實(shí)現(xiàn)隨機(jī)點(diǎn)名(實(shí)例代碼)

JS常用正則表達(dá)式總結(jié)【經(jīng)典】

Bootstrap Tree View簡(jiǎn)單而優(yōu)雅的樹(shù)結(jié)構(gòu)組件實(shí)例解析

簡(jiǎn)單實(shí)現(xiàn)Bootstrap標(biāo)簽頁(yè)