<div id="example">
<component :is="component_name" @click="ccl()"></component>
</div>
var mycomponent = Vue.extend({
template: '<div>{{title}}hello component.</div>',
props: ['message'],
data: function () {
return {title: this.$root.message}
},
methods: {
ccl: function () {
alert('right');
}
}
});
不是这么写的么?为什么我点击了以后没有反应呢?报错为VM9342:3 Uncaught TypeError: scope.ccl is not a function
这个ccl不是组件的,而是他爹的方法。
你要在他爹的methods里面定义:
理解好vue模板里面的作用域,就能够知道为什么了。。。
========2016年9月22日16:01:39 补充===========
这个文档有说啊,用props:
然后父组件在data里面弄个msg的字段
vue的作者尤大的文档写的很详细啦~~~~认真看下都会明白的