diff --git a/src/image/README.md b/src/image/README.md index 67ccd0444..7206cfddb 100644 --- a/src/image/README.md +++ b/src/image/README.md @@ -74,6 +74,7 @@ Vue.use(Lazyload); | height | Height | `string | number` | - | - | | round | Whether to be round | `boolean` | `false` | - | | lazy-load | Whether to enable lazy load,should 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 diff --git a/src/image/README.zh-CN.md b/src/image/README.zh-CN.md index e90a569c9..ad26551fd 100644 --- a/src/image/README.zh-CN.md +++ b/src/image/README.zh-CN.md @@ -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 | ### 图片填充模式 diff --git a/src/image/index.js b/src/image/index.js index 72cb02b72..1ef7ab96d 100644 --- a/src/image/index.js +++ b/src/image/index.js @@ -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 (
{this.slots('error') || } diff --git a/src/image/test/__snapshots__/index.spec.js.snap b/src/image/test/__snapshots__/index.spec.js.snap index 418dab8bb..dbe794b5d 100644 --- a/src/image/test/__snapshots__/index.spec.js.snap +++ b/src/image/test/__snapshots__/index.spec.js.snap @@ -26,3 +26,5 @@ exports[`load event 2`] = ` `; exports[`loading-placeholder prop 1`] = `
`; + +exports[`show-error prop 1`] = `
`; diff --git a/src/image/test/index.spec.js b/src/image/test/index.spec.js index 4f3042429..29e9bc37e 100644 --- a/src/image/test/index.spec.js +++ b/src/image/test/index.spec.js @@ -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(); +});