5_v-on.html 983 B

1234567891011121314151617181920212223242526272829303132333435
  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. <div>{{str}}</div>
  11. <!-- v-on: 事件绑定指令 可以将事件绑定到标签上 -->
  12. <!-- v-on: 可以缩写为 @ -->
  13. <!-- <button v-on:click="changeStr">按钮</button> -->
  14. <button @click="changeStr">按钮</button>
  15. </div>
  16. <script src="./js/vue.js"></script>
  17. <script>
  18. new Vue({
  19. el:"#app",
  20. data:{
  21. str:"hello world"
  22. },
  23. // vue2当中用来定义函数及事件处理函数的地方
  24. methods:{
  25. changeStr(){
  26. // console.log("按钮被点击了");
  27. console.log(this.str);
  28. this.str = "你好世界";
  29. }
  30. }
  31. })
  32. </script>
  33. </body>
  34. </html>