代码:
<!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>