How to do it...

The following bit of code shows how to react to a click event:

  1. Fill in the following HTML:
        <div id="app">           <button v-on:click="toast">Toast bread</button>         </div>
  1. As for the JavaScript, write the following:
        new Vue({el:'#app', methods:{toast(){alert('Tosted!')}}})
  1. Run the code! An event listener will be installed on the button.
  2. Click the button and you should see a popup that says Toasted!

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.