vue04.html 915 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>模板</title>
  6. <!-- 引入文件 -->
  7. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!-- number -->
  12. <h3 v-if="number==1" > 好好学习 </h3>
  13. <h2 v-else > 天天向上 </h2>
  14. <h3 v-show="number == 1" > 好好学习 </h3>
  15. <h2 v-show="number != 1" > 天天向上 </h2>
  16. <button @click="changeBut">改变</button>
  17. </div>
  18. </body>
  19. <script>
  20. const { createApp, ref } = Vue;
  21. createApp({
  22. setup() {
  23. let number = ref(1);
  24. function changeBut(){
  25. number.value = 2;
  26. }
  27. return {
  28. number,changeBut
  29. };
  30. }
  31. }).mount('#app'); //createApp创建对象 挂在到app
  32. </script>
  33. </html>