Advertisement
serg_specialist

Untitled

Nov 22nd, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="https://unpkg.com/vue"></script>
  9. </head>
  10. <body>
  11. <div id="app">
  12. <h1>{{message}}</h1>
  13. <div>Price: {{productPrice}}</div>
  14. <div>Price (method call):{{getProductPrice()}}</div>
  15. <div> {{calc(2)}} </div>
  16. <div> Результат выражения = {{ 2 * 2}} </div>
  17. <div> Counter: {{counter}}</div>
  18. <!-- директива v-on -->
  19. <button v-on:click="onClick">OK1</button>
  20. <!-- сокращенный синтаксис для определения обработчиков событий -->
  21. <button @click="onClick">OK2</button>
  22. <button @click="inc">Увеличить counter!!!</button>
  23. <pre>{{ $data }}</pre>
  24. </div>
  25. <script>
  26. let vm = new Vue({
  27. el: "#app",
  28. data: {
  29. message: "Привет, Vue!",
  30. productPrice: 1000,
  31. counter: 1
  32. },
  33. methods: {
  34. getProductPrice: function(){
  35. // используется ключевое слово this
  36. return this.productPrice;
  37. },
  38. calc: function(n){
  39. console.log(n);
  40. },
  41. // метод обработчик событий !!!
  42. onClick: function(){
  43. alert("onClick invoked!!!!");
  44. },
  45. inc: function(){
  46. this.counter++;
  47. }
  48. }
  49. })
  50. </script>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement