Blogger Information
Blog 37
fans 0
comment 0
visits 14455
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue3安装 (v-text、v-bind、v-on、v-model) 使用
秋闲独醉
Original
472 people have browsed it

  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>第一个vue页面</title>
  8. <script src="https://unpkg.com/vue@next"></script>
  9. <!-- <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> -->
  10. <style>
  11. .active {
  12. color: orange;
  13. }
  14. .bgc {
  15. background-color: blue;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="firstVue">
  21. <!-- 页面模板化:模板字面量 -->
  22. <p>{{content}}</p>
  23. <!-- v-text 相当于textContent -->
  24. <p v-text="name"></p>
  25. <!-- v-html 相当于innerHTML -->
  26. <p v-html="address"></p>
  27. <div>
  28. <!-- 行内样式 v-bind:style -->
  29. <!-- v-bind 可以简写成 : -->
  30. <p v-bind:style="{color:textColor,}">我是行内样式</p>
  31. <p v-bind:style="mycolor">我是行内样式2</p>
  32. <p v-bind:style="[mycolor]">我是行内样式3</p>
  33. </div>
  34. <div>
  35. <!-- class 类样式 -->
  36. <p v-bind:class="['active']">我是class样式</p>
  37. <p v-bind:class="[myactive]">我是class样式2</p>
  38. <p v-bind:class="{active:flag}">我是class样式3</p>
  39. <p class="bgc">我是原生class样式4</p>
  40. </div>
  41. <div>
  42. <!-- 数据双向绑定 -->
  43. <!-- 原生js -->
  44. <p>
  45. <input type="text" name="" id="" oninput="this.nextElementSibling.textContent = this.value" />
  46. <span></span>
  47. </p>
  48. <!-- Vue双向数据绑定 v-on -->
  49. <!-- $event 事件对象, 在vue不能直接用event -->
  50. <!-- <p>
  51. <input type="text" style="background-color: gray" v-on:input="comment=$event.currentTarget.value" v-bind:value="comment" />
  52. <span>{{comment}}</span
  53. >
  54. </p> -->
  55. <!-- Vue双向数据绑定 v-on -->
  56. <!-- $event 事件对象, 在vue不能直接用event -->
  57. <!-- 简写v-on: === @ ; v-bind: === : -->
  58. <!-- <p>
  59. <input type="text" style="background-color: yellow" @input="comment=$event.currentTarget.value" :value="comment" />
  60. <span>{{comment}}</span>
  61. </p> -->
  62. <!-- 简写 v-model === v-on:input="comment = $event.currentTarget.value" -->
  63. <!-- <p><input type="text" style="background: orange" v-model="comment" :value="comment" /> <span>{{comment}}</span></p> -->
  64. <!-- 延迟绑定:修饰符 .lazy -->
  65. <p><input type="text" style="background: orange" v-model.lazy="comment" :value="comment" /> <span>{{comment}}</span></p>
  66. </div>
  67. </div>
  68. <script>
  69. const app = Vue.createApp({
  70. data() {
  71. return {
  72. content: "这是一个Vue",
  73. name: "这是一个v-text",
  74. address: "<i>这是一个v-html</i>",
  75. textColor: "red",
  76. mycolor: {
  77. color: "red",
  78. },
  79. myactive: "active",
  80. flag: true,
  81. comment: "",
  82. };
  83. },
  84. });
  85. app.mount("#firstVue");
  86. </script>
  87. </body>
  88. </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