if-else3.html 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>1.引入VUE</title>
  6. <meta charset="UTF-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  9. <link href="../css/style.css" rel="stylesheet"> </head>
  10. </head>
  11. <body>
  12. <div id="app">
  13. <h1>您的成绩评价</h1>
  14. <div>
  15. score: {{score}} {{strResult}}
  16. </div>
  17. <div>
  18. <button @click="btnClick">改变</button>
  19. </div>
  20. </div>
  21. <script>
  22. new Vue({
  23. el: '#app',
  24. data: {
  25. score: 0,
  26. strResult: "",
  27. },
  28. methods: {
  29. btnClick: function() {
  30. this.score = Math.round(Math.random() * 100);
  31. if(this.score < 60)
  32. this.strResult = "不及格";
  33. else if(this.score < 80)
  34. this.strResult = "中等生";
  35. else if(this.score <= 100)
  36. this.strResult = "优秀生";
  37. },
  38. },
  39. })
  40. </script>
  41. </body>
  42. </html>