Skip to content

Instantly share code, notes, and snippets.

@cn-2k
Created March 18, 2022 13:03
Show Gist options
  • Save cn-2k/e806e6d73f30e3f33d90ab535d359bba to your computer and use it in GitHub Desktop.
Save cn-2k/e806e6d73f30e3f33d90ab535d359bba to your computer and use it in GitHub Desktop.
V-Model usage with <script setup> and computed
<template>
<div>
<input v-model="model">
</div>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
modelValue: {
type: [String, Number],
default: ''
}
})
const emit = defineEmits(['update:modelValue'])
const model = computed({
get () {
return props.modelValue
},
set (value) {
return emit('update:modelValue', value)
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment