クリックしたらその名前のイベントを発火するだけのディレクティブを作った。自分は処理の委譲の為にこれ作らんと話にならなかったので。
Vue.directive 'dispatcher',
isLiteral: true
bind: (value) ->
@el.addEventListener 'click', =>
@vm.$dispatch(@expression)
v = new Vue
template: """<button v-dispatcher="message"></button>"""
v.$on 'message', ->
console.log 'message clicked'
最初ViewModelのインスタンスを得る方法がわからなかったのだけど、リファレンス読んだらちゃんと書いてあった。
el: the element the directive is bound to.
key: the keypath of the binding, excluding arguments and filters.
arg: the argument, if present.
expression: the raw, unparsed expression.
vm: the context ViewModel that owns this directive.
value: the current binding value.