Blogger Information
Blog 28
fans 0
comment 0
visits 13021
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
声明组件与子组件,以及他们之间的通信方式
手机用户1594223549
Original
567 people have browsed it

代码部分

  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>声明组件与子组件,以及他们之间的通信方式</title>
  8. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  9. </head>
  10. <body>
  11. <!-- 挂载点 -->
  12. <div id="app">
  13. <!-- 组件挂载 -->
  14. <greeting />
  15. </div>
  16. </body>
  17. <script>
  18. // 应用实例
  19. const app = Vue.createApp({});
  20. app.component("greeting", {
  21. // html模版
  22. template: `
  23. <h2>Hello, {{uname}}</h2>
  24. <button @click='setLike'>点赞 + {{count}}</button>
  25. <!-- 命名规则: 小驼 -> 肉串 -->
  26. <my-award v-if='count >=10' />
  27. `,
  28. // 数据
  29. data() {
  30. return {
  31. uname: "李老师",
  32. count: 0,
  33. };
  34. },
  35. // 方法
  36. methods: {
  37. setLike() {
  38. this.count++;
  39. },
  40. },
  41. // 声明子组件(复数属性)
  42. components: {
  43. // 奖励组件
  44. myAward: {
  45. // 只要是组件,可以写模版
  46. template: `<p>实在太受欢迎了`,
  47. data() {
  48. return {};
  49. },
  50. components: {},
  51. },
  52. },
  53. });
  54. // 根组件实例 (vue应用与挂载点绑定)
  55. const vm = app.mount("#app");
  56. </script>
  57. </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