15.事件修饰.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <div id="app">
  10. <!-- v-on:"事件名"="事件方法" => @事件名"="事件方法" -->
  11. <!-- 键盘事件
  12. @keydown/@keyup/@keypress.修饰字符
  13. -->
  14. <!--
  15. 修饰符:
  16. 触发一次 .once
  17. 阻止默认行为 .prevent
  18. 阻止事件冒泡 .stop
  19. 触发自身 .self
  20. .... .native ...
  21. -->
  22. <input type="text" v-on:keydown.g="showMain">
  23. <div @click.once="part1">哈哈哈哈</div>
  24. <a @click.prevent="part2" href="http://www.baidu.com">大大大大大大</a>
  25. <div @click="part3" style="width: 300px;height: 300px;background-color: red;">
  26. <div @click.stop="part4" style="width: 100px;height: 100px;background-color: #ff0;"></div>
  27. </div>
  28. <div @click.self="part5" style="width: 300px;height: 300px;background-color: red;margin-top: 100px;">
  29. <div @click="part6" style="width: 100px;height: 100px;background-color: #ff0;"></div>
  30. </div>
  31. </div>
  32. <script src="./vue.js"></script>
  33. <script>
  34. var vm = new Vue({
  35. methods: {
  36. showMain() {
  37. console.log("按下")
  38. },
  39. part1() {
  40. console.log("点击")
  41. },
  42. part2() {
  43. console.log("哒哒哒")
  44. },
  45. part3() {
  46. console.log("333")
  47. },
  48. part4() {
  49. console.log("444")
  50. },
  51. part5() {
  52. console.log("555")
  53. },
  54. part6() {
  55. console.log("666")
  56. },
  57. },
  58. }).$mount("#app")
  59. </script>
  60. </body>
  61. </html>