Blogger Information
Blog 36
fans 1
comment 0
visits 26399
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue基本语法与常用指令
早晨
Original
417 people have browsed it

Vue基本语法与常用指令

代码:

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>Vue基本语法与常用指令</title>
  8. <script src="https://unpkg.com/vue@next"></script>
  9. <style>
  10. .te {
  11. color: red;
  12. }
  13. .bg {
  14. background-color: yellow;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <!-- 插值 -->
  20. <h1 class="title">{{message}}</h1>
  21. <hr />
  22. <!-- 挂载点 -->
  23. <div class="app">
  24. <p>挂载点:你好,{{username}}</p>
  25. </div>
  26. <hr />
  27. <div class="vhtml">
  28. <p>V-HTML: 你好,<span v-html="username"></span></p>
  29. </div>
  30. <hr />
  31. <div class="vtext">
  32. <p>V-TEXT:你好, <span v-text="username"></span></p>
  33. </div>
  34. <hr />
  35. <div class="hn">
  36. <!-- 1. 行内: style -->
  37. <p :style="{color:textColor,backgroundColor: bg}">XXXXX.XXX</p>
  38. <p :style="[base, custom]">XXX.XXX</p>
  39. <!-- 2. 类样式: class -->
  40. <p :class="te">你好,小小明</p>
  41. <!-- classList -->
  42. <p :class="{te: isActive}">你好,小小红</p>
  43. <!-- v-bind:简化为冒号 -->
  44. <p :class="['te', 'bg']">Hello 王老师</p>
  45. <p :class="[mycolor, mybgc]">Hello 王老师</p>
  46. </div>
  47. <script>
  48. const apps = Vue.createApp({
  49. data() {
  50. return {
  51. message: "Hello 大家吃了吗",
  52. };
  53. },
  54. });
  55. apps.mount(document.querySelector(".title"));
  56. // 挂载点
  57. const app = Vue.createApp({
  58. data() {
  59. return {
  60. username: "小明同学",
  61. };
  62. },
  63. }).mount(".app");
  64. // v - html
  65. const vhtml = Vue.createApp({
  66. data() {
  67. return {
  68. username: "",
  69. };
  70. },
  71. }).mount(".vhtml");
  72. vhtml.username = '<i style="color:red">张同学</i>';
  73. // v-text
  74. const vtext = Vue.createApp({
  75. data() {
  76. return {
  77. username: "小蓝同学",
  78. };
  79. },
  80. }).mount(".vtext");
  81. const hn = Vue.createApp({
  82. data() {
  83. return {
  84. textColor: "green",
  85. bgc: "wheat",
  86. base: {
  87. border: "1px solid",
  88. background: "lightgreen",
  89. },
  90. custom: {
  91. color: "white",
  92. padding: "15px",
  93. },
  94. active: "te",
  95. isActive: true,
  96. mycolor: "te",
  97. mybgc: "bg",
  98. };
  99. },
  100. }).mount(".hn");
  101. </script>
  102. </body>
  103. </html>

运行效果

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!