首页 > 请问如何在vue中通过data把父组件中的方法传到子组件?

请问如何在vue中通过data把父组件中的方法传到子组件?

一个弹出框的子组件,在父组件引用,想要在父组件中,给弹出框的按钮设置不同放方法。比如:

//父组件
<v-popup :popupdata="popupdata"></v-popup>

data (){  
    popupdata: {
      title:"提示",
      content:"您有一份奖品,请点击",
      btntext:[
        {"text":"确认","meth":this.surepopup},
        {"text":"取消","meth":this.closepopup}
      ]
    },
    
},
methods:{
  surepopup:function(){
    console.log("sure")
  },
  closepopup:function(){
    console.log("close")
  }
}

//子组件
<div class="popup confirm">
<div class="mask"></div>
<div class="content">
    <h3 v-text="popupdata.title"></h3>
    <div class="" v-text="popupdata.content"></div>
    <div class="popup-btn col-flex">
        <div class="col-flex-2 singleLineTop" v-for="btnt in popupdata.btntext"  @touchstart="btnt.meth" v-text="btnt.text"></div>
    </div>
    </div>
</div>


    props:[
        "popupdata"
    ],

在这里我是想通过父组件中data里面数据,给不同的按钮分配不同放方法,然后到子组件中的@touchstart="btnt.meth"这里调用,发现没有效果。
不知道有没有别的方式,可以做到这种需求。


http://cn.vuejs.org/guide/com...
vue的官网是中文的,还来这里问。。。。

【热门文章】
【热门文章】