简体   繁体   中英

Get v-model value in child component Vue

I am using a Vue2Editor in my Vuetify App. I have made a component of text-editor as:

<vue-editor
  :value="text"
  @input="updateText"
></vue-editor>

And it's props are:

props: {
  text: {
    type: String,
    required: true
  }
},

For the validation, I am calling it in the parent component and giving it v-model (VeeValidate requires it) :

<text-editor
  :text="UnitData.Details"
  v-model="UnitData.Details"
  @updateText="UnitData.Details = $event"
  data-vv-name="details"
  v-validate="'required|min:100'"
/>

Now look, text and v-model have same values, I need to get v-model in my child component (used vModel prop but not worked) , so that I don't end up with duplicate code, any suggestions?

text-editor component:

<vue-editor
  :value="value"
  @input="updateText"
></vue-editor>
props: {
  value: {
    type: String,
    required: true
  }
},
methods: {
  updateText () {
    this.$emit('input', this.value)
  }
}

parent

<text-editor
  v-model="UnitData.Details"
/>

See https://v2.vuejs.org/v2/guide/components.html#Using-v-model-on-Components

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM