Open moh1434 opened 1 year ago
This snippet make setup typescript script with props and emits.
<template> <div> </div> </template> <script setup lang="ts"> export interface Props { user?: string } const props = withDefaults(defineProps<Props>(), { user: 'foo' }) const emits = defineEmits<{ (e: 'update:user', newValue: string): void }>() const onClick = () => emits('update:user', 'bar'); //in parent component: // v-model:user="userParentVariable" //OR: // :user="userParentVariable" @update:user="userParentVariable = event" </script> <style scoped> </style>
This snippet make setup typescript script with props and emits.