Created
May 4, 2022 04:49
-
-
Save okyungjin/12109650c1020dabc683ee13ec466195 to your computer and use it in GitHub Desktop.
[Vue 3] Set default value to props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. destrcuting 사용 | |
const { | |
label = 'Normal Button', | |
borderRadius, | |
borderColor = 'transparent', | |
backgroundColor = '#FF4800', | |
} = defineProps<Props>(); | |
// 2. withDefaults 사용 | |
const props = withDefaults(defineProps<Props>(), { | |
label: 'Normal Button', | |
borderColor: 'transparent', | |
backgroundColor: '#FF4800', | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1번 방법은 사용하면 안 된다. label이라는 key가 없을 때 기본 값이 설정되지 않기 때문!