vue父组件传方法给子组件

在父组件中

<div id="app">

   <com2 v-on:func="show"></com2>

</div>

com2就是引入父组件中的子组件

子组件模板

<template id="temp1">

      <div>

         <h1>这是一个子组件</h1>

        <input type="button" @click="myclick">

     </div>

</teamplate>

定义的字面量

var com2={

   template:'temp1',

   methods:{

     this.$emit(func)

}

}

父组件的js代码

var vue=new Vue({

  el:'#app',

  data:{},

  methods:{

  show():{

       console.log("调用了父组件的show方法")

    }

},

  components:{

    com2

}

}) 

发布了58 篇原创文章 · 获赞 11 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/ducaijia_123/article/details/96605751