Created
March 18, 2022 13:03
-
-
Save cn-2k/e806e6d73f30e3f33d90ab535d359bba to your computer and use it in GitHub Desktop.
V-Model usage with <script setup> and computed
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
<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