Cheat sheet

Component information

Vue.component('my-component',  {
   props:  {     The parameters the component accepts
      myMessage:  String,
      product:   Object,
      email:  {
         type:  String,
         required:  true,
         default:  "test@test.com"
         validator:  function  (value)  {
            Return true or false
         }
      }
   },
   data:  function()  {      Must be a function
      return  {
         firstName:  'Vue' ,
         lastName:  'Info'
      }
   },
   methods:  {  ...  }
   computed:  (       Return values cached until
      fullName:  function  ()  { dependencies change
         return  this.firstName  +  '  '  +  this.lastName
      }
   }
   watch:  {        Called when firstName changes value
      firstName:  function  (value,  oldValue)  {  ..  }
   },
   components:  { components that can be used in the template
      ButtonComponent,  IconComponent
   },
   template:  ' <span>{{  myMessage  }}</span>',
})            Can also use ...

Get Vue.js in Action 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.