Created
July 14, 2021 15:34
-
-
Save mattmaribojoc/a02bd6bf325b7f961b68ea07bb99b856 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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