Vue.jsでメソッドを定義して任意の場所で処理を呼び出すことが出来ます。
実装例
| js |
|---|
|
var app = new Vue({ el: '#app', methods: { helloAlert: function(){ alert('Hello!') }, }, }) |
| html |
|---|
|
<div id="app"> <button v-on:click="helloAlert">Push!</button> </div> |
ボタンを押すとアラートが出現する実装です。