I'm new to VUE and trying to learn composition API.
I'm trying to write a simple two-way binding for a text box, but the value under the {{xyz}} does not update, am I doing something wrong?
I believe for Vue2 it was just having a v-bind and {{}} for this.
App.vue
<template>
<div>
Original Text Box
<textBox :value="text"></textBox>
Two Way Binding:
{{ text }}
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import textBox from '../src/components/HelloWorld.vue'
export default defineComponent({
name: 'HomePage',
components: {
textBox
},
setup() {
const text = ref('Inital Value')
return { text }
}
})
</script>
<style scoped>
</style>
HellowWorld.vue
<template>
<div>
<textarea v-model="props.value"></textarea>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'TEXTBOX',
props: { value: String },
setup(props) {
console.log(props.value)
return { props }
}
})
</script>
<style scoped>
</style>
Output: When the app loads
After updating the text value:


Use
v-modelandmodelValuefor the two-way binding.Don't use
propsfor two-way binding, since they are readonly.Check the Vue Docs Component v-model to understand how
v-modeltwo-way binding works with components.Do not
return { props }fromsetup()Playground