perf(radio): 新增 radio 组件 change 事件

This commit is contained in:
就眠仪式 2021-10-13 13:10:37 +08:00
parent aac27992c0
commit 1cc6e529c0
4 changed files with 111 additions and 16 deletions

View File

@ -0,0 +1,86 @@
::: demo
<template>
<lay-form>
<lay-radio v-model="selected1" name="action" label="1">写作</lay-radio>
<lay-radio v-model="selected1" name="action" label="2">画画</lay-radio>
<lay-radio v-model="selected1" name="action" label="3">运动</lay-radio>
</lay-form>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const selected1 = ref("1");
return {
selected
}
}
}
</script>
:::
::: demo
<template>
<lay-form>
<lay-radio v-model="selected2" name="action" label="1">写作</lay-radio>
<lay-radio v-model="selected2" name="action" label="2">画画</lay-radio>
<lay-radio v-model="selected2" name="action" label="3">运动</lay-radio>
<lay-radio v-model="selected2" name="action" label="4" :disabled="disabled">禁用</lay-radio>
</lay-form>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const disabled = ref(true);
const selected2 = ref("1");
return {
disabled,
selected2
}
}
}
</script>
:::
::: demo
<template>
<lay-form>
<lay-radio v-model="selected3" name="action" label="1" @change="change">写作</lay-radio>
<lay-radio v-model="selected3" name="action" label="2" @change="change">画画</lay-radio>
<lay-radio v-model="selected3" name="action" label="3" @change="change">运动</lay-radio>
</lay-form>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const selected3 = ref("1");
const change = function( current ) {
console.log("当前值:" + current)
}
return {
selected3,
change
}
}
}
</script>
:::

View File

@ -278,6 +278,11 @@ export default {
title: '复选框', title: '复选框',
subTitle: 'checkbox', subTitle: 'checkbox',
path: '/zh-CN/components/checkbox', path: '/zh-CN/components/checkbox',
},{
id: 33,
title: '单选框',
subTitle: 'radio',
path: '/zh-CN/components/radio',
}, },
] ]

View File

@ -178,6 +178,10 @@ const zhCN = [
path: '/zh-CN/components/checkbox', path: '/zh-CN/components/checkbox',
component: () => import('../../docs/zh-CN/components/checkbox.md'), component: () => import('../../docs/zh-CN/components/checkbox.md'),
meta: { title: '复选框' }, meta: { title: '复选框' },
},{
path: '/zh-CN/components/radio',
component: () => import('../../docs/zh-CN/components/radio.md'),
meta: { title: '单选框' },
}, },
], ],
}, },

View File

@ -7,20 +7,18 @@
'layui-form-radioed': modelValue == label, 'layui-form-radioed': modelValue == label,
'layui-radio-disbaled layui-disabled': disabled, 'layui-radio-disbaled layui-disabled': disabled,
}" }"
@click="handleClick" @click.stop="handleClick"
> >
<i
v-if="modelValue != label"
class="layui-anim layui-icon layui-anim-scaleSpring"
:class="{ 'layui-form-radioed': modelValue != label }"
>&#xe63f;</i
>
<i <i
v-if="modelValue == label" v-if="modelValue == label"
class="layui-anim layui-icon layui-anim-scaleSpring" class="layui-anim layui-icon layui-anim-scaleSpring"
:class="{ 'layui-form-radioed': modelValue == label }"
>&#xe643;</i >&#xe643;</i
> >
<i
v-else
class="layui-anim layui-icon layui-anim-scaleSpring layui-form-radioed"
>&#xe63f;</i
>
<span><slot /></span> <span><slot /></span>
</div> </div>
</span> </span>
@ -29,19 +27,21 @@
<script setup name="LayRadio" lang="ts"> <script setup name="LayRadio" lang="ts">
import { defineProps, defineEmits } from 'vue' import { defineProps, defineEmits } from 'vue'
const props = defineProps<{ const props =
modelValue: string defineProps<{
disabled?: boolean modelValue: string
label?: string disabled?: boolean
name: string label?: string
}>() name: string
}>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue','change'])
const handleClick = function () { const handleClick = function () {
if (props.disabled) { if (props.disabled) {
return false return
} }
emit('change', props.label)
emit('update:modelValue', props.label) emit('update:modelValue', props.label)
} }
</script> </script>