Commit d564f077d4e22213d997f0c09100b3bcc9d5e5f7
Committed by
GitHub
Merge pull request #3255 from xiaofengsha/pr003
Card组件增加title和icon属性,简化用户使用
Showing
1 changed file
with
15 additions
and
3 deletions
Show diff stats
src/components/card/card.vue
1 | 1 | <template> |
2 | 2 | <div :class="classes"> |
3 | - <div :class="headClasses" v-if="showHead"><slot name="title"></slot></div> | |
3 | + <div :class="headClasses" v-if="showHead"><slot name="title"> | |
4 | + <p v-if="title"> | |
5 | + <Icon v-if="icon" :type="icon"></Icon> | |
6 | + {{title}} | |
7 | + </p> | |
8 | + </slot></div> | |
4 | 9 | <div :class="extraClasses" v-if="showExtra"><slot name="extra"></slot></div> |
5 | 10 | <div :class="bodyClasses" :style="bodyStyles"><slot></slot></div> |
6 | 11 | </div> |
... | ... | @@ -8,10 +13,11 @@ |
8 | 13 | <script> |
9 | 14 | const prefixCls = 'ivu-card'; |
10 | 15 | const defaultPadding = 16; |
16 | + import Icon from '../icon/icon.vue'; | |
11 | 17 | |
12 | 18 | export default { |
13 | 19 | name: 'Card', |
14 | - | |
20 | + components: { Icon }, | |
15 | 21 | props: { |
16 | 22 | bordered: { |
17 | 23 | type: Boolean, |
... | ... | @@ -28,6 +34,12 @@ |
28 | 34 | padding: { |
29 | 35 | type: Number, |
30 | 36 | default: defaultPadding |
37 | + }, | |
38 | + title: { | |
39 | + type: String, | |
40 | + }, | |
41 | + icon: { | |
42 | + type: String, | |
31 | 43 | } |
32 | 44 | }, |
33 | 45 | data () { |
... | ... | @@ -67,7 +79,7 @@ |
67 | 79 | } |
68 | 80 | }, |
69 | 81 | mounted () { |
70 | - this.showHead = this.$slots.title !== undefined; | |
82 | + this.showHead = this.title || this.$slots.title !== undefined; | |
71 | 83 | this.showExtra = this.$slots.extra !== undefined; |
72 | 84 | } |
73 | 85 | }; | ... | ... |