黄子涵

摘要: 当构建一个 <blog-post> 组件时,你的模板最终会包含的东西远不止一个标题: <h3>{{ title }}</h3> 最最起码,你会包含这篇博文的正文: <h3>{{ title }}</h3> <div v-html="content"></div> 然而如果你在模板中尝试这样写,Vue 阅读全文
posted @ 2022-06-03 22:30 黄子涵 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 早些时候,我们提到了创建一个博文组件的事情。问题是如果你不能向这个组件传递某一篇博文的标题或内容之类的我们想展示的数据的话,它是没有办法使用的。这也正是 prop 的由来。 Prop 是你可以在组件上注册的一些自定义 attribute。当一个值传递给一个 prop attribute 的时候,它就 阅读全文
posted @ 2022-06-03 21:54 黄子涵 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 通常一个应用会以一棵嵌套的组件树的形式来组织: 例如,你可能会有页头、侧边栏、内容区等组件,每个组件又包含了其它的像导航链接、博文之类的组件。 为了能在模板中使用,这些组件必须先注册以便 Vue 能够识别。这里有两种组件的注册类型:全局注册和局部注册。至此,我们的组件都只是通过Vue.compone 阅读全文
posted @ 2022-06-03 21:36 黄子涵 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 你可以将组件进行任意次数的复用: <div id="components-demo"> <button-counter></button-counter> <button-counter></button-counter> <button-counter></button-counter> </di 阅读全文
posted @ 2022-06-03 21:30 黄子涵 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 这里有一个 Vue 组件的示例: // 定义一个名为 button-counter 的新组件 Vue.component('button-counter', { data: function () { return { count: 0 } }, template: '<button v-on:cl 阅读全文
posted @ 2022-06-03 21:27 黄子涵 阅读(24) 评论(0) 推荐(0) 编辑