2_v-on.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. <style>
  9. #div1{
  10. width: 200px;
  11. height: 200px;
  12. background: red;
  13. }
  14. #div2{
  15. width: 100px;
  16. height: 100px;
  17. background: yellow;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="app">
  23. {{msg}} <br>
  24. <!-- @ v-on:click = 'con' -->
  25. <button @click="con">点击</button>
  26. <div id="div1" @click="fn1">
  27. <div id="div2" @click="fn2"></div>
  28. </div>
  29. <input type="text" @keyup="key">
  30. <input type="text" @keyup.enter="keyOne">
  31. </div>
  32. <script src="vue.js"></script>
  33. <script>
  34. var app = new Vue({
  35. el: '#app',
  36. data: {
  37. msg: 'hello word'
  38. },
  39. methods: {
  40. con(){
  41. alert(123)
  42. },
  43. fn1(){
  44. console.log('我是红色')
  45. },
  46. fn2(){
  47. console.log('我是黄色')
  48. },
  49. key(){
  50. console.log('111')
  51. },
  52. keyOne(){
  53. console.log('我是回车')
  54. }
  55. }
  56. })
  57. </script>
  58. </body>
  59. </html>