子组件:
<template>
  <button @click="clickme">点击我</button>
</template>
<script>
export default {
  data() {
    return {
      message: "我是要传递的数据"
    }
  },
  methods: {
    clickme(){
      this.$emit('my-click', this.message)
    }
  }
}
</script>


父组件:
<template>
  <div ></child-a>
    <!--父组件中通过监测my-event事件执行一个方法,然后取到子组件中传递过来的值-->
  </div>
</template>
<script>
import sonfrom './components/son.vue'
export default {
  components: {
    son
  },
  methods: {
    getMessage(msg){
      console.log(msg)
    }
  }
}
</script>

相关文章:

  • 2021-06-21
  • 2022-12-23
  • 2021-05-26
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-07-10
  • 2022-01-02
  • 2021-07-06
  • 1970-01-01
  • 2021-07-31
  • 2021-10-22
  • 2021-10-29
相关资源
相似解决方案