1.天气案例.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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>天气案例</title>
  8. <!-- 引入vue -->
  9. <script type="text/javascript" src="../js/vue.js"></script>
  10. </head>
  11. <body>
  12. <!-- 准备好一个容器 -->
  13. <div id="root">
  14. <h2>今天天气很{{info}}</h2>
  15. <!-- 绑定事件的时候:@xxx="yyy" yyy可以写一些简单的语句 -->
  16. <button @click="isHot = !isHot">切换天气</button>
  17. <!-- <button @click="changeWeathers">切换天气</button> -->
  18. </div>
  19. </body>
  20. <script type="text/javascript">
  21. Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示
  22. new Vue({
  23. el:'#root',
  24. data:{
  25. isHot:true
  26. },
  27. computed:{
  28. info(){
  29. return this.isHot ? '炎热' : '凉爽'
  30. }
  31. },
  32. methods: {
  33. // changeWeathers(){
  34. // this.isHot = !this.isHot
  35. // }
  36. },
  37. })
  38. </script>
  39. </html>