练习1_累加器.html 941 B

12345678910111213141516171819202122232425262728293031323334353637
  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. <script src="./js/vue.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <h1 v-if="num>=10">已经最大数字</h1>
  12. <h1 v-else>当前数字:{{num}}</h1>
  13. <button @click="addFun">累加</button>
  14. </div>
  15. <script>
  16. new Vue({
  17. el:"#app",
  18. data:{
  19. num:0
  20. },
  21. methods:{
  22. addFun(){
  23. // 方法一
  24. // if(this.num<10){
  25. // this.num++;
  26. // }else{
  27. // this.num = "已到最大值";
  28. // }
  29. // 方法二
  30. this.num++;
  31. }
  32. }
  33. })
  34. </script>
  35. </body>
  36. </html>