Advertisement
deyanivanov966

Section 4 Events

Feb 12th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. --> Click event
  2. Onclick event
  3.  
  4. 1. <template>
  5. 2. <button v-on:click="count++">Add 1</button>
  6. 3. <p>Count is: {{ count }}</p>
  7. 4. </template>
  8. 5. <script>
  9. 6. export default {
  10. 7. name: "Hello",
  11. 8. data() {
  12. 9. return {
  13. 10. count: 0
  14. 11. }
  15. 12. }
  16. 13. }
  17. 14. </script>
  18.  
  19.  
  20. --> Call a function onclick
  21. Call a function onclick
  22.  
  23. 1. <template>
  24. 2. <button v-on:click="getAge()">GetAge</button>
  25. 3. </template>
  26. 4. <script>
  27. 5. export default {
  28. 6. name: "Hello",
  29. 7. methods: {
  30. 8. getAge() {
  31. 9. alert(26)
  32. 10. }
  33. 11. }
  34. 12. }
  35. 13. </script>
  36.  
  37.  
  38. --> Pass params with event
  39.  
  40. 1. <template>
  41. 2. <button v-on:click="getAge(25)">GetAge</button>
  42. 3. </template>
  43. 4. <script>
  44. 5. export default {
  45. 6. name: "Hello",
  46. 7. methods: {
  47. 8. getAge(data) {
  48. 9. alert(data)
  49. 10. }
  50. 11. }
  51. 12. }
  52. 13. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement