1. 程式人生 > >vue 子元件呼叫父元件方法

vue 子元件呼叫父元件方法

父元件vue

<privateScoreTop  :msg ="Widget" v-on:listenTochildEvent="showMessageFromChild">
</privateScoreTop>

父元件js

export default{
    data(){
        return {
        }
    },
    computed:{
      privateScoreTop : ()=>import("./privateScoreTop.vue")  
    },
    mounted(){
    },
    methods
:{ showMessageFromChild(data){ console.log("回掉子元件成功"+data); } } }

子元件js

export default{
    methods: {
      onfilter(){
          this.$emit("listenTochildEvent",{回傳引數});
       },
    }
}