06_事件.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <script src="../vue.js"></script>
  7. </head>
  8. <body>
  9. <div id="app" >
  10. <!-- 参数 m没有参数 默认e 写参数 () 当前对象 其他 字符串 -->
  11. <button v-on:click="method1($event,'hello')" >按钮1</button>
  12. <!-- 简写 @click-->
  13. <button @click="method1($event,'hello')" >按钮2</button>
  14. <!-- 下拉框 -->
  15. name:<input type="text" @change="method2" v-model = "message" >
  16. <!-- a 标签 默认行为 -->
  17. <a href="https://baidu.com" @click="baidu">百度一下</a>
  18. <a href="https://baidu.com" @click.prevent="baidu">百度一下</a>
  19. </div>
  20. </body>
  21. <script>
  22. var jsonParam = {
  23. el: "#app",
  24. data: {
  25. message: "hello"
  26. },
  27. methods:{
  28. // 通过方法名()
  29. method1(e,t){
  30. console.log(e)
  31. console.log(t)
  32. console.log("点击事件别调用")
  33. },
  34. //change
  35. method2(){
  36. console.log(this.message)
  37. },
  38. //baidu
  39. baidu(){
  40. console.log("阻止默认事件")
  41. }
  42. }
  43. }
  44. var vue = new Vue(jsonParam);
  45. </script>
  46. </html>