Radio Group
Vue 已实现 · 还原验收 0/2 · 上游演示 · 固定版本源码
预览
用法
vue
<script setup lang="ts">
import { RadioGroup } from 'beui-vue'
import { ref, onBeforeUnmount, onMounted, shallowRef } from 'vue'
function usePreviewVariant(alternate: string) {
const variant = shallowRef('default')
function sync() {
const requested = new URLSearchParams(location.search).get('variant')
variant.value = requested === alternate ? alternate : 'default'
}
function select(name: string) {
const url = new URL(location.href)
url.searchParams.set('variant', name)
history.replaceState(history.state, '', url)
sync()
}
onMounted(() => { sync(); window.addEventListener('popstate',sync) })
onBeforeUnmount(() => window.removeEventListener('popstate',sync))
return { variant, select }
}
const { variant, select } = usePreviewVariant('description')
const plan = ref('pro')
const schedule = ref('once')
const schedules = [
{value:'once', label:'Run once', detail:'Runs a single time, right now.'},
{value:'schedule', label:'Run on a schedule', detail:'Repeats on a set interval until stopped.'},
{value:'trigger', label:'Run on a trigger', detail:'Waits for an event before it starts.'},
{value:'manual', label:'Manual approval', detail:'Not available on your plan.',disabled:true},
]
const options = [
{ value: 'starter', label: 'Starter, free' },
{ value: 'pro', label: 'Pro, $12/mo' },
{ value: 'team', label: 'Team, $29/mo' },
{ value: 'legacy', label: 'Legacy plan', disabled: true },
]
</script>
<template><div class="choices"><label>Example <select :value="variant" @change="select(($event.target as HTMLSelectElement).value)"><option value="default">Default</option><option value="description">Description</option></select></label>
<RadioGroup v-if="variant==='description'" v-model="schedule" :options="schedules" label="Scheduling"/>
<RadioGroup v-else v-model="plan" :options="options" label="Plans" />
</div></template>
<style scoped>.choices { display:grid; gap:1rem; }</style>API
options 定义单选项,v-model 绑定选择,label 说明分组用途。保留原生表单和方向键操作。