Skip to content

Commit f91d0a2

Browse files
wangyi7099yyx990803
authored andcommitted
docs: add example for nested custom components (#195)
1 parent 9159604 commit f91d0a2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/.vuepress/components/Foo/Bar.vue

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<p class="demo">
3+
{{ msg }}
4+
</p>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data () {
10+
return {
11+
msg: 'Hello this is <Foo-Bar>'
12+
}
13+
}
14+
}
15+
</script>

docs/guide/using-vue.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,25 @@ Any `*.vue` files found in `.vuepress/components` are automatically registered a
103103
└─ .vuepress
104104
  └─ components
105105
├─ demo-1.vue
106-
    └─ OtherComponent.vue
106+
    ├─ OtherComponent.vue
107+
     └─ Foo
108+
        └─ Bar.vue
107109
```
108110

109111
Inside any markdown file you can then directly use the components (names are inferred from filenames):
110112

111113
``` md
112114
<demo-1/>
113115
<OtherComponent/>
116+
<Foo-Bar/>
114117
```
115118

116119
<demo-1></demo-1>
117120

118121
<OtherComponent/>
119122

123+
<Foo-Bar/>
124+
120125
::: warning IMPORTANT
121126
Make sure a custom component's name either contains a hyphen or is in PascalCase. Otherwise it will be treated as an inline element and wrapped inside a `<p>` tag, which will lead to hydration mismatch because `<p>` does not allow block elements to be placed inside it.
122127
:::

docs/zh/guide/using-vue.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,25 @@ export default {
103103
└─ .vuepress
104104
  └─ components
105105
├─ demo-1.vue
106-
    └─ OtherComponent.vue
106+
    ├─ OtherComponent.vue
107+
     └─ Foo
108+
        └─ Bar.vue
107109
```
108110

109111
你可以直接使用这些组件在任意的 Markdown 文件中(组件名是通过文件名取到的):
110112

111113
``` md
112114
<demo-1/>
113115
<OtherComponent/>
116+
<Foo-Bar/>
114117
```
115118

116119
<demo-1></demo-1>
117120

118121
<OtherComponent/>
119122

123+
<Foo-Bar/>
124+
120125
::: warning 重要!
121126
请确保一个自定义组件的名字包含连接符或者是 PascalCase,否则,它将会被视为一个内联元素,并被包裹在一个 `<p>` 标签中,这将会导致 HTML 渲染紊乱,因为 HTML 标准规定, `<p>` 标签中不允许放置任何块级元素。
122127
:::

0 commit comments

Comments
 (0)