Created
May 13, 2020 22:08
-
-
Save GavinRay97/29f9af2f84665e5656e8298a568f1175 to your computer and use it in GitHub Desktop.
Vue 3 Composition API Typescript Component Props
This file contains 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
import { defineComponent, computed, ref } from '@vue/composition-api' | |
interface User { | |
firstName: string | |
lastName: number | |
} | |
export default defineComponent({ | |
props: { | |
user: { | |
type: Object as () => User, | |
required: true | |
} | |
}, | |
setup ({ user }) { | |
const fullName = computed(() => `${user.firstName} ${user.lastName}`) | |
const message = ref('This is a message') | |
return { | |
fullName, | |
message | |
} | |
} | |
}) |
error Destructuring the props
will cause the value to lose reactivity
Yes, that's right! But the typecasting of the prop still works even if you don't destructure the props in setup()
~
FYI, for folks who want to know the rule - https://eslint.vuejs.org/rules/no-setup-props-destructure.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow! Thanks for this tip! 👍