How to use enum in defineProps #7171
Unanswered
qwhatevera
asked this question in
Help/Questions
Replies: 2 comments
-
The macro In the demo enum MSG {
'msg1',
'msg2'
}
interface Props {
msg: MSG,
name: string
}
defineProps<Props>() will transform to ...
props: {
msg: { type: null, required: true },
name: { type: String, required: true }
},
... I suggest you to use plugin to support enum in the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Are you struggling with how to set an attribute type in props as an enum, for example, the following enum: enum SIZE {
LARGElarge',
MEDIUM = 'medium',
SMALL = 'small',
} define props: import { defineProps } from 'vue'
const props = defineProps<{ size: SIZE }>()
pros.size // size: SIZE If you need the default import { defineProps, withDefaults } from 'vue'
const props = withDefaults(defineProps<{ size: SIZE }>(), { size: SIZE.MEDIUM })
props.size // size: SIZE
console.log(props.size)
// medium |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How to use enum in defineProps
Beta Was this translation helpful? Give feedback.
All reactions