Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

vue.js - Passing v-model to Child Component

I'm using Vue 3. In the example below I have 3 simple components, Name Component, Phone Component and Submit Component. How do I get in the respective properties of the Submit Component, what was entered in the inputs?

Name Component:

<template>
  <div>
    <input type="text" v-bind="name">
  </div>
</template>

Phone Component:

<template>
  <div>
    <input type="text" v-bind="phone">
  </div>
</template>

Submit Component:

<template>
  <name></name>
  <phone></phone>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      phone: '',
    }
  }
}
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    <template>
   <section>
      <childComponent ref="nameOfRef" />
   </section>
</template>

 methods: {
  submit() {
   let Data = this.$refs.nameOfRef.$data; // nameOfRef.data or nameOfRef.$data or nameOfRef.phone or nameOfRef.name
 }
},

Check I think it will help to catch your parent component data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...