[new feature] Image: add show-error prop (#3896)

This commit is contained in:
neverland 2019-07-19 09:50:03 +08:00 committed by GitHub
parent 250babecaa
commit 157d0bfee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 2 deletions

View File

@ -74,6 +74,7 @@ Vue.use(Lazyload);
| height | Height | `string | number` | - | - |
| round | Whether to be round | `boolean` | `false` | - |
| lazy-load | Whether to enable lazy loadshould register [Lazyload](#/en-US/lazyload) component | `boolean` | `false` | - |
| show-error | Whether to show error placeholder | `boolean` | `true` |
| loading-placeholder | Whether to show loading placeholder | `boolean` | `true` |
### fit optional value

View File

@ -100,7 +100,8 @@ Vue.use(Image);
| height | 高度,默认单位为 px | `string | number` | - | - |
| round | 是否显示为圆形 | `boolean` | `false` | - |
| lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `boolean` | `false` | - |
| loading-placeholder | 是否展示图片加载中提示 | `boolean` | `true` | `2.0.9` |
| show-error | 是否展示图片加载失败提示 | `boolean` | `true` | 2.0.9 |
| loading-placeholder | 是否展示图片加载中提示 | `boolean` | `true` | 2.0.9 |
### 图片填充模式

View File

@ -12,6 +12,10 @@ export default createComponent({
width: [Number, String],
height: [Number, String],
lazyLoad: Boolean,
showError: {
type: Boolean,
default: true
},
loadingPlaceholder: {
type: Boolean,
default: true
@ -103,7 +107,7 @@ export default createComponent({
);
}
if (this.error) {
if (this.error && this.showError) {
return (
<div class={bem('error')}>
{this.slots('error') || <Icon name="warning-o" size="22" />}

View File

@ -26,3 +26,5 @@ exports[`load event 2`] = `
`;
exports[`loading-placeholder prop 1`] = `<div class="van-image"><img class="van-image__img"></div>`;
exports[`show-error prop 1`] = `<div class="van-image"></div>`;

View File

@ -111,3 +111,16 @@ test('loading-placeholder prop', () => {
expect(wrapper).toMatchSnapshot();
});
test('show-error prop', () => {
const wrapper = mount(Image, {
propsData: {
showError: false,
src: 'https://img.yzcdn.cn/vant/cat.jpeg'
}
});
wrapper.find('img').trigger('error');
expect(wrapper).toMatchSnapshot();
});