diff --git a/packages/card/en-US.md b/packages/card/en-US.md index 3a219fa42..39b36b453 100644 --- a/packages/card/en-US.md +++ b/packages/card/en-US.md @@ -58,6 +58,12 @@ Use slot to custom content. | thumb-link | Thumb link URL | `String` | - | | lazy-load | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` | +### Event + +| Event | Description | Arguments | +|------|------|------| +| click | Triggered when clicked | - | + ### Slot | name | Description | diff --git a/packages/card/index.js b/packages/card/index.js index 05d16705e..e208e532f 100644 --- a/packages/card/index.js +++ b/packages/card/index.js @@ -3,89 +3,105 @@ import Tag from '../tag'; const [sfc, bem] = use('card'); -export default sfc({ - props: { - tag: String, - desc: String, - thumb: String, - title: String, - centered: Boolean, - lazyLoad: Boolean, - thumbLink: String, - num: [Number, String], - price: [Number, String], - originPrice: [Number, String], - currency: { - type: String, - default: '¥' - } - }, +function Card(h, props, slots, ctx) { + const { thumb } = props; - render(h) { - const { thumb, slots } = this; + const showThumb = slots.thumb || thumb; + const showTag = slots.tag || props.tag; + const showNum = slots.num || isDef(props.num); + const showPrice = slots.price || isDef(props.price); + const showOriginPrice = slots['origin-price'] || isDef(props.originPrice); - const showThumb = slots('thumb') || thumb; - const showTag = slots('tag') || this.tag; - const showNum = slots('num') || isDef(this.num); - const showPrice = slots('price') || isDef(this.price); - const showOriginPrice = slots('origin-price') || isDef(this.originPrice); - - const Thumb = showThumb && ( - - {slots('thumb') || - (this.lazyLoad ? ( - + const Thumb = showThumb && ( + + {slots.thumb ? ( + slots.thumb() + ) : props.lazyLoad ? ( + + ) : ( + + )} + {showTag && ( +
+ {slots.tag ? ( + slots.tag() ) : ( - - ))} - {showTag && ( -
- {slots('tag') || ( - - {this.tag} - - )} -
- )} -
+ + {props.tag} + + )} +
+ )} + + ); + + const Title = slots.title + ? slots.title() + : props.title &&
{props.title}
; + + const Desc = slots.desc + ? slots.desc() + : props.desc && ( +
{props.desc}
); - const Title = slots('title') || (this.title &&
{this.title}
); + const Price = showPrice && ( +
+ {slots.price ? slots.price() : `${props.currency} ${props.price}`} +
+ ); - const Desc = - slots('desc') || (this.desc &&
{this.desc}
); + const OriginPrice = showOriginPrice && ( +
+ {slots['origin-price'] + ? slots['origin-price'] + : `${props.currency} ${props.originPrice}`} +
+ ); - const Price = showPrice && ( -
{slots('price') || `${this.currency} ${this.price}`}
- ); + const Num = showNum && ( +
{slots.num ? slots.num() : `x ${props.num}`}
+ ); - const OriginPrice = showOriginPrice && ( -
- {slots('origin-price') || `${this.currency} ${this.originPrice}`} -
- ); + const Footer = slots.footer && ( +
{slots.footer()}
+ ); - const Num = showNum &&
{slots('num') || `x ${this.num}`}
; - - const Footer = slots('footer') &&
{slots('footer')}
; - - return ( -
-
- {Thumb} -
- {Title} - {Desc} - {slots('tags')} -
- {Price} - {OriginPrice} - {Num} -
+ return ( +
+
+ {Thumb} +
+ {Title} + {Desc} + {slots.tags && slots.tags()} +
+ {Price} + {OriginPrice} + {Num}
- {Footer}
- ); + {Footer} +
+ ); +} + +Card.props = { + tag: String, + desc: String, + thumb: String, + title: String, + centered: Boolean, + lazyLoad: Boolean, + thumbLink: String, + num: [Number, String], + price: [Number, String], + originPrice: [Number, String], + currency: { + type: String, + default: '¥' } -}); +}; + +export default sfc(Card); diff --git a/packages/card/zh-CN.md b/packages/card/zh-CN.md index 363b8dadf..61472f886 100644 --- a/packages/card/zh-CN.md +++ b/packages/card/zh-CN.md @@ -58,6 +58,12 @@ Vue.use(Card); | thumb-link | 点击左侧图片后的跳转链接 | `String` | - | 1.3.4 | | lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.0 | +### Event + +| 事件名 | 说明 | 参数 | +|------|------|------| +| click | 点击时触发 | - | + ### Slot | 名称 | 说明 |