Commit 737e2df88bec9a0f9b4f52dddf7b1c39950ee0e2
1 parent
d45d2ee0
* Card组件增加title和icon属性,简化用户使用
Showing
1 changed file
with
12 additions
and
4 deletions
Show diff stats
src/components/card/card.vue
| 1 | <template> | 1 | <template> |
| 2 | <div :class="classes"> | 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"><Icon v-if="icon" :type="icon"></Icon>{{title}}</p> | ||
| 5 | + </slot></div> | ||
| 4 | <div :class="extraClasses" v-if="showExtra"><slot name="extra"></slot></div> | 6 | <div :class="extraClasses" v-if="showExtra"><slot name="extra"></slot></div> |
| 5 | <div :class="bodyClasses" :style="bodyStyles"><slot></slot></div> | 7 | <div :class="bodyClasses" :style="bodyStyles"><slot></slot></div> |
| 6 | </div> | 8 | </div> |
| @@ -8,10 +10,10 @@ | @@ -8,10 +10,10 @@ | ||
| 8 | <script> | 10 | <script> |
| 9 | const prefixCls = 'ivu-card'; | 11 | const prefixCls = 'ivu-card'; |
| 10 | const defaultPadding = 16; | 12 | const defaultPadding = 16; |
| 11 | - | 13 | + import Icon from '../icon/index' |
| 12 | export default { | 14 | export default { |
| 13 | name: 'Card', | 15 | name: 'Card', |
| 14 | - | 16 | + components: { Icon }, |
| 15 | props: { | 17 | props: { |
| 16 | bordered: { | 18 | bordered: { |
| 17 | type: Boolean, | 19 | type: Boolean, |
| @@ -28,6 +30,12 @@ | @@ -28,6 +30,12 @@ | ||
| 28 | padding: { | 30 | padding: { |
| 29 | type: Number, | 31 | type: Number, |
| 30 | default: defaultPadding | 32 | default: defaultPadding |
| 33 | + }, | ||
| 34 | + title: { | ||
| 35 | + type: String, | ||
| 36 | + }, | ||
| 37 | + icon: { | ||
| 38 | + type: String, | ||
| 31 | } | 39 | } |
| 32 | }, | 40 | }, |
| 33 | data () { | 41 | data () { |
| @@ -67,7 +75,7 @@ | @@ -67,7 +75,7 @@ | ||
| 67 | } | 75 | } |
| 68 | }, | 76 | }, |
| 69 | mounted () { | 77 | mounted () { |
| 70 | - this.showHead = this.$slots.title !== undefined; | 78 | + this.showHead = this.title || this.$slots.title !== undefined; |
| 71 | this.showExtra = this.$slots.extra !== undefined; | 79 | this.showExtra = this.$slots.extra !== undefined; |
| 72 | } | 80 | } |
| 73 | }; | 81 | }; |