今天剛學習 vue 有一個問題想請教
假設我已經有一個 component 如下
var Component = Vue.extend({
methods: function () {
print: function () {
console.log('Go')
}
}
});
Vue.component('component', Component);
可否在 HTML 中直接 bind methods 呢?或者說該怎麼做能夠做到動態放入子元素但能用父元件的方法
<component>
<button v-on:click="print">Print</button>
</component>
大家讲道理2017-04-10 17:15:52
var Button= Vue.extend({
methods: function () {
print: function () {
this.$dispatch('print','123')
}
}
});