Skip to Content
Vue.js 2 Cookbook
book

Vue.js 2 Cookbook

by Andrea Passaglia
April 2017
Intermediate to advanced
454 pages
12h 51m
English
Packt Publishing
Content preview from Vue.js 2 Cookbook

Two-way data binding

The v-on attribute will have you covered in most cases, especially if the event comes from the element. On the other hand, it may sometimes be too verbose for some tasks.

For example, if we had a textbox and we wanted to update a variable with the content of the textbox and ensure that the textbox always has an updated value of the variable (which is called two-way data binding), we would have to write a couple of handlers.

Instead, this operation is carried out by the v-model attribute, as the following code shows:

<div id="app">   <button v-on:click="toast">Toast bread</button>   <input v-model="toastedBreads" />   Quantity to put in the oven: {{toastedBreads}} </div>new Vue({   el: '#app',   methods: {     toast () {  this.toastedBreads++ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Vue.js 2

Learning Vue.js 2

Olga Filipova
Pro Vue.js 2

Pro Vue.js 2

Adam Freeman

Publisher Resources

ISBN: 9781786468093Supplemental Content