Skip to content

Instantly share code, notes, and snippets.

@mattmaribojoc
Created July 14, 2021 15:34
Show Gist options
  • Save mattmaribojoc/a02bd6bf325b7f961b68ea07bb99b856 to your computer and use it in GitHub Desktop.
Save mattmaribojoc/a02bd6bf325b7f961b68ea07bb99b856 to your computer and use it in GitHub Desktop.
<template>
<div>
<input
type="text"
:value="data"
@input="update"
/>
</div>
</template>
<script>
import { useVModel } from '@vueuse/core'
export default {
props: ['data'],
setup(props, { emit }) {
const data = useVModel(props, 'data', emit)
console.log(data.value) // equal to props.data
data.value = 'name' // equal to emit('update:data', 'name')
const update = (event) => {
data.value = event.target.value
}
return {
data,
update
}
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment