iview/src/components/card/card.vue

87 lines
2.4 KiB
Vue
Raw Normal View History

2016-09-15 23:43:50 +08:00
<template>
<div :class="classes">
<div :class="headClasses" v-if="showHead"><slot name="title">
2018-03-29 10:39:15 +08:00
<p v-if="title">
<Icon v-if="icon" :type="icon"></Icon>
{{title}}
</p>
</slot></div>
2017-03-03 10:46:19 +08:00
<div :class="extraClasses" v-if="showExtra"><slot name="extra"></slot></div>
2017-03-17 12:37:31 +08:00
<div :class="bodyClasses" :style="bodyStyles"><slot></slot></div>
2016-09-15 23:43:50 +08:00
</div>
</template>
<script>
const prefixCls = 'ivu-card';
2017-03-21 14:50:32 +08:00
const defaultPadding = 16;
2018-03-29 10:39:15 +08:00
import Icon from '../icon/icon.vue';
2016-09-15 23:43:50 +08:00
export default {
2017-07-12 11:08:51 -05:00
name: 'Card',
components: { Icon },
2016-09-15 23:43:50 +08:00
props: {
bordered: {
type: Boolean,
default: true
},
disHover: {
type: Boolean,
default: false
},
shadow: {
type: Boolean,
default: false
2017-03-17 12:37:31 +08:00
},
2017-03-21 14:50:32 +08:00
padding: {
type: Number,
default: defaultPadding
},
title: {
type: String,
},
icon: {
type: String,
2017-03-21 14:50:32 +08:00
}
2016-09-15 23:43:50 +08:00
},
data () {
return {
showHead: true,
showExtra: true
2016-12-25 22:49:42 +08:00
};
2016-09-15 23:43:50 +08:00
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-bordered`]: this.bordered && !this.shadow,
[`${prefixCls}-dis-hover`]: this.disHover || this.shadow,
[`${prefixCls}-shadow`]: this.shadow
}
2016-12-25 22:49:42 +08:00
];
2016-09-15 23:43:50 +08:00
},
headClasses () {
return `${prefixCls}-head`;
},
extraClasses () {
return `${prefixCls}-extra`;
},
bodyClasses () {
return `${prefixCls}-body`;
2017-03-17 12:37:31 +08:00
},
bodyStyles () {
2017-03-21 14:50:32 +08:00
if (this.padding !== defaultPadding) {
2017-03-17 12:37:31 +08:00
return {
2017-03-21 14:50:32 +08:00
padding: `${this.padding}px`
};
2017-03-21 14:50:32 +08:00
} else {
return '';
2017-03-17 12:37:31 +08:00
}
2016-09-15 23:43:50 +08:00
}
},
2017-03-02 17:35:02 +08:00
mounted () {
this.showHead = this.title || this.$slots.title !== undefined;
2017-03-03 10:46:19 +08:00
this.showExtra = this.$slots.extra !== undefined;
2016-09-15 23:43:50 +08:00
}
2016-12-25 22:49:42 +08:00
};
</script>