Advertisement
Guest User

asdads

a guest
Feb 19th, 2016
2,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <template>
  3.  
  4.     Counter: {{ counter }}
  5.     <button v-on:click="incCounter()">
  6.         Inc
  7.     </button>
  8.  
  9.     <br/><br/>
  10.     Remaining to 10: {{ remainingTo10() }}
  11.  
  12. </template>
  13.  
  14. <script>
  15.  
  16.     class TestComp {
  17.  
  18.         // equivalent of "data()" - here declare all variables
  19.         // that will become reactive after constructing class
  20.         constructor() {
  21.             this.counter = 0;
  22.         }
  23.  
  24.         // lifecycle event - could be prefixed with $ for clarification
  25.         // that it is internally-called method instead of standard user
  26.         // event handler
  27.         $ready() {
  28.             window.alert( 'Our component is ready!' );
  29.         }
  30.  
  31.         // standard user event handler (eg clicking button)
  32.         incCounter() {
  33.             this.counter++;
  34.         }
  35.  
  36.         // computed property
  37.         remainingTo10() {
  38.             return 10 - this.counter;
  39.         }
  40.  
  41.     }
  42.  
  43.     export default TestComp;
  44.  
  45. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement