Skip to content

Commit 3c9c58f

Browse files
author
savoygu
committed
Add title slot support
1 parent 19d56b8 commit 3c9c58f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

example/src/App.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
</thead>
262262
<tbody>
263263
<tr>
264-
<td>multiple <i class="vd-demo__new">(特殊标识)</i></td>
264+
<td>multiple</td>
265265
<td>是否同时展示多个示例</td>
266266
<td>boolean</td>
267267
<td>—</td>
@@ -329,7 +329,11 @@
329329
<th>参数</th>
330330
<th>说明</th>
331331
</thead>
332-
<tbody>
332+
<tbody>
333+
<tr>
334+
<td>title <i class="vd-demo__new">(1.0.1 新增)</i></td>
335+
<td>标题</td>
336+
</tr>
333337
<tr>
334338
<td>description</td>
335339
<td>标题描述</td>

lib/vue-demonstration.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Demo.vue

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<vd-demo-title
44
:title="title"
55
:anchor="anchor"
6-
:tag="tag"></vd-demo-title>
6+
:tag="tag"
7+
:has-slot="!!$slots.title"></vd-demo-title>
78
<vd-demo-description
89
:description="description"
910
:has-slot="!!$slots.description">
@@ -53,8 +54,14 @@
5354
type: String,
5455
default: ''
5556
},
56-
title: String,
57-
description: String,
57+
title: {
58+
type: String,
59+
default: ''
60+
},
61+
description: {
62+
type: String,
63+
default: ''
64+
},
5865
showContent: {
5966
type: Boolean,
6067
default: true
@@ -101,11 +108,11 @@
101108
props: {
102109
title: String,
103110
anchor: String,
104-
tag: String
111+
tag: String,
112+
hasSlot: Boolean
105113
},
106114
render (h) {
107-
if (this.title) {
108-
return h(this.tag, {
115+
return h(this.tag, {
109116
attrs: {
110117
id: this.anchor
111118
}
@@ -121,10 +128,8 @@
121128
innerHTML: ''
122129
}
123130
}),
124-
this.title
131+
this.title ? this.title : (this.hasSlot ? this.$parent.$slots.title : '' )
125132
])
126-
}
127-
return ''
128133
}
129134
},
130135
'vd-demo-description': {

0 commit comments

Comments
 (0)