mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Card: functional (#2740)
This commit is contained in:
parent
7a1ed98eb7
commit
a152309cfc
@ -58,6 +58,12 @@ Use slot to custom content.
|
|||||||
| thumb-link | Thumb link URL | `String` | - |
|
| thumb-link | Thumb link URL | `String` | - |
|
||||||
| lazy-load | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
|
| 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
|
### Slot
|
||||||
|
|
||||||
| name | Description |
|
| name | Description |
|
||||||
|
@ -3,89 +3,105 @@ import Tag from '../tag';
|
|||||||
|
|
||||||
const [sfc, bem] = use('card');
|
const [sfc, bem] = use('card');
|
||||||
|
|
||||||
export default sfc({
|
function Card(h, props, slots, ctx) {
|
||||||
props: {
|
const { thumb } = 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: '¥'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
render(h) {
|
const showThumb = slots.thumb || thumb;
|
||||||
const { thumb, slots } = this;
|
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 Thumb = showThumb && (
|
||||||
const showTag = slots('tag') || this.tag;
|
<a href={props.thumbLink} class={bem('thumb')}>
|
||||||
const showNum = slots('num') || isDef(this.num);
|
{slots.thumb ? (
|
||||||
const showPrice = slots('price') || isDef(this.price);
|
slots.thumb()
|
||||||
const showOriginPrice = slots('origin-price') || isDef(this.originPrice);
|
) : props.lazyLoad ? (
|
||||||
|
<img class={bem('img')} vLazy={thumb} />
|
||||||
const Thumb = showThumb && (
|
) : (
|
||||||
<a href={this.thumbLink} class={bem('thumb')}>
|
<img class={bem('img')} src={thumb} />
|
||||||
{slots('thumb') ||
|
)}
|
||||||
(this.lazyLoad ? (
|
{showTag && (
|
||||||
<img class={bem('img')} vLazy={thumb} />
|
<div class={bem('tag')}>
|
||||||
|
{slots.tag ? (
|
||||||
|
slots.tag()
|
||||||
) : (
|
) : (
|
||||||
<img class={bem('img')} src={thumb} />
|
<Tag mark type="danger">
|
||||||
))}
|
{props.tag}
|
||||||
{showTag && (
|
</Tag>
|
||||||
<div class={bem('tag')}>
|
)}
|
||||||
{slots('tag') || (
|
</div>
|
||||||
<Tag mark type="danger">
|
)}
|
||||||
{this.tag}
|
</a>
|
||||||
</Tag>
|
);
|
||||||
)}
|
|
||||||
</div>
|
const Title = slots.title
|
||||||
)}
|
? slots.title()
|
||||||
</a>
|
: props.title && <div class={bem('title')}>{props.title}</div>;
|
||||||
|
|
||||||
|
const Desc = slots.desc
|
||||||
|
? slots.desc()
|
||||||
|
: props.desc && (
|
||||||
|
<div class={[bem('desc'), 'van-ellipsis']}>{props.desc}</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const Title = slots('title') || (this.title && <div class={bem('title')}>{this.title}</div>);
|
const Price = showPrice && (
|
||||||
|
<div class={bem('price')}>
|
||||||
|
{slots.price ? slots.price() : `${props.currency} ${props.price}`}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const Desc =
|
const OriginPrice = showOriginPrice && (
|
||||||
slots('desc') || (this.desc && <div class={[bem('desc'), 'van-ellipsis']}>{this.desc}</div>);
|
<div class={bem('origin-price')}>
|
||||||
|
{slots['origin-price']
|
||||||
|
? slots['origin-price']
|
||||||
|
: `${props.currency} ${props.originPrice}`}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const Price = showPrice && (
|
const Num = showNum && (
|
||||||
<div class={bem('price')}>{slots('price') || `${this.currency} ${this.price}`}</div>
|
<div class={bem('num')}>{slots.num ? slots.num() : `x ${props.num}`}</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const OriginPrice = showOriginPrice && (
|
const Footer = slots.footer && (
|
||||||
<div class={bem('origin-price')}>
|
<div class={bem('footer')}>{slots.footer()}</div>
|
||||||
{slots('origin-price') || `${this.currency} ${this.originPrice}`}
|
);
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
const Num = showNum && <div class={bem('num')}>{slots('num') || `x ${this.num}`}</div>;
|
return (
|
||||||
|
<div class={bem()} {...ctx.data}>
|
||||||
const Footer = slots('footer') && <div class={bem('footer')}>{slots('footer')}</div>;
|
<div class={bem('header')}>
|
||||||
|
{Thumb}
|
||||||
return (
|
<div class={bem('content', { centered: props.centered })}>
|
||||||
<div class={bem()}>
|
{Title}
|
||||||
<div class={bem('header')}>
|
{Desc}
|
||||||
{Thumb}
|
{slots.tags && slots.tags()}
|
||||||
<div class={bem('content', { centered: this.centered })}>
|
<div class="van-card__bottom">
|
||||||
{Title}
|
{Price}
|
||||||
{Desc}
|
{OriginPrice}
|
||||||
{slots('tags')}
|
{Num}
|
||||||
<div class="van-card__bottom">
|
|
||||||
{Price}
|
|
||||||
{OriginPrice}
|
|
||||||
{Num}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{Footer}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
{Footer}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
@ -58,6 +58,12 @@ Vue.use(Card);
|
|||||||
| thumb-link | 点击左侧图片后的跳转链接 | `String` | - | 1.3.4 |
|
| thumb-link | 点击左侧图片后的跳转链接 | `String` | - | 1.3.4 |
|
||||||
| lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.0 |
|
| lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.0 |
|
||||||
|
|
||||||
|
### Event
|
||||||
|
|
||||||
|
| 事件名 | 说明 | 参数 |
|
||||||
|
|------|------|------|
|
||||||
|
| click | 点击时触发 | - |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
|
||||||
| 名称 | 说明 |
|
| 名称 | 说明 |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user