3

my child component is like this

<editor v-model="edit_thread.body"></editor>

and then I access the component from inside like this

<template>
    <div>
        <input :value="this.value">
    </div>
</template>

<script>
    export default {
        data() {
            return {
                value: this.edit_thread.body
            }
        }
    }
</script>

not working, I miss something?

tony19
  • 125,647
  • 18
  • 229
  • 307
angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • Possible duplicate of [Update parent model from child component Vue](https://stackoverflow.com/questions/41663010/update-parent-model-from-child-component-vue) – Julian Sep 24 '18 at 04:43

1 Answers1

7

To use v-model on custom components, the component needs to:

  • have a prop (not a data property) named value:

     <template>
       <div>
         <input :value="value">
       </div>
     </template>
    
     <script>
     export default {
       props: ['value']
     }
     </script>
    
  • and emit an input event with new values:

     <template>
       <div>
         <input @input="$emit('input', $event.target.value)">
       </div>
     </template>
    

demo

tony19
  • 125,647
  • 18
  • 229
  • 307