wd-radio-group.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <view :class="`wd-radio-group ${customClass} ${cell && shape === 'button' ? 'is-button' : ''}`" :style="customStyle">
  3. <slot />
  4. </view>
  5. </template>
  6. <script lang="ts">
  7. export default {
  8. name: 'wd-radio-group',
  9. options: {
  10. virtualHost: true,
  11. addGlobalClass: true,
  12. styleIsolation: 'shared'
  13. }
  14. }
  15. </script>
  16. <script lang="ts" setup>
  17. import { watch } from 'vue'
  18. import { useChildren } from '../composables/useChildren'
  19. import { RADIO_GROUP_KEY, radioGroupProps } from './types'
  20. const props = defineProps(radioGroupProps)
  21. const emit = defineEmits(['change', 'update:modelValue'])
  22. const { linkChildren, children } = useChildren(RADIO_GROUP_KEY)
  23. linkChildren({ props, updateValue })
  24. watch(
  25. () => props.shape,
  26. (newValue) => {
  27. // type: 'dot', 'button', 'check'
  28. const type = ['check', 'dot', 'button']
  29. if (type.indexOf(newValue) === -1) console.error(`shape must be one of ${type.toString()}`)
  30. },
  31. { deep: true, immediate: true }
  32. )
  33. /**
  34. * @description 处理radio子节点通知
  35. */
  36. function updateValue(value: string | number | boolean) {
  37. emit('update:modelValue', value)
  38. emit('change', {
  39. value
  40. })
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. @import './index.scss';
  45. </style>