Skip to content

Instantly share code, notes, and snippets.

@alquezajanmaverick
Last active October 13, 2022 00:49
Show Gist options
  • Save alquezajanmaverick/fd642a263e31304f79c5c5fcbd1d30d8 to your computer and use it in GitHub Desktop.
Save alquezajanmaverick/fd642a263e31304f79c5c5fcbd1d30d8 to your computer and use it in GitHub Desktop.
Vue 3 SFC v-model
<script setup>
const props = defineProps({
modelValue: String
})
const emit = defineEmits(['update:modelValue'])
function updateValue(value) {
emit('update:modelValue', value)
}
</script>
<template>
<input
type="text"
:placeholder="props.label"
:value="props.modelValue"
v-on:input="updateValue($event.target.value)"
/>
</template>
<script setup>
import { ref } from 'vue'
import Child from './Child.vue'
const name = ref('')
</script>
<template>
<Child v-model="name"/>
<p>{{ name }}</p>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment