原理是: 子组件使用$emit发送数据,父组件使用$on,或者v-on绑定, 来监听子组件发送的数据。

子组件:

<button @click="sendChildData">点击我将子组件的数据传递给父组件</button>
data () {
    return {
        childData: 111
    }
  },
  methods:{
      sendChildData(){
          this.$emit('sendtoFu',this.childData);
      }
  }

父组件:

<子组件 @sendtoFu="getChildData"></子组件>
<div>这是子组件传递过来的数据 --->   {{  isMe }} </div>
data() {
    return {
      isMe : ''
    }
  },
  methods:{
    getChildData(data){
      this.isMe = data;
    }
  },

相关文章:

  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-05-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2020-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
相关资源
相似解决方案