代码:

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
</head>

<body>
  <div id="app">
    <child :fun="parentFun"></child>
  </div>
  <script src="http://cdn.bootcss.com/vue/1.0.17/vue.js"></script>
  <script>
    'use strict';
    Vue.component('child', {
      template: '<div @click="useFun">点击子组件调用父组件里的方法</div>',
      name: 'child',
      props: {
        fun: Function
      },
      created() {

      },
      methods: {
        useFun() {
          this.fun()
        }
      }

    })

    new Vue({
      el: '#app',
      data() {
        return {

        }
      },
      methods: {
        parentFun() {
          console.log(111)
        }
      }
    })
  </script>
</body>

</html>

我的一个道姑朋友
80 声望4 粉丝

星光不问赶路人,岁月不负有心人。