From 01e9cde2b88720b9c92171c4a6896b6da26f5263 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 26 Jun 2020 17:36:10 +0800 Subject: [PATCH] feat(Image): add default slot (#6613) --- src/image/README.md | 9 +++++---- src/image/README.zh-CN.md | 9 +++++---- src/image/index.js | 1 + src/image/test/__snapshots__/index.spec.js.snap | 7 +++++++ src/image/test/index.spec.js | 13 +++++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/image/README.md b/src/image/README.md index 791cd823c..2b3bb1bf9 100644 --- a/src/image/README.md +++ b/src/image/README.md @@ -98,7 +98,8 @@ Vue.use(Lazyload); ### Slots -| Name | Description | -| ------- | -------------------------- | -| loading | Custom loading placeholder | -| error | Custom error placeholder | +| Name | Description | +| ---------------- | ---------------------------------- | +| default `v2.9.0` | Custom the content below the image | +| loading | Custom loading placeholder | +| error | Custom error placeholder | diff --git a/src/image/README.zh-CN.md b/src/image/README.zh-CN.md index 3e5116529..adf57f026 100644 --- a/src/image/README.zh-CN.md +++ b/src/image/README.zh-CN.md @@ -130,10 +130,11 @@ Vue.use(Lazyload); ### Slots -| 名称 | 说明 | -| ------- | -------------------------- | -| loading | 自定义加载中的提示内容 | -| error | 自定义加载失败时的提示内容 | +| 名称 | 说明 | +| ---------------- | -------------------------- | +| default `v2.9.0` | 自定义图片下方的内容 | +| loading | 自定义加载中的提示内容 | +| error | 自定义加载失败时的提示内容 | ## 常见问题 diff --git a/src/image/index.js b/src/image/index.js index be8b2d1ef..4f426b951 100644 --- a/src/image/index.js +++ b/src/image/index.js @@ -173,6 +173,7 @@ export default createComponent({ > {this.genImage()} {this.genPlaceholder()} + {this.slots()} ); }, diff --git a/src/image/test/__snapshots__/index.spec.js.snap b/src/image/test/__snapshots__/index.spec.js.snap index 4dbffdaac..95dbee240 100644 --- a/src/image/test/__snapshots__/index.spec.js.snap +++ b/src/image/test/__snapshots__/index.spec.js.snap @@ -1,5 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`default slot 1`] = ` +
+
+
Custom Default +
+`; + exports[`error-icon prop 1`] = `
diff --git a/src/image/test/index.spec.js b/src/image/test/index.spec.js index 716766078..28529a564 100644 --- a/src/image/test/index.spec.js +++ b/src/image/test/index.spec.js @@ -157,3 +157,16 @@ test('radius prop', () => { expect(wrapper).toMatchSnapshot(); }); + +test('default slot', () => { + const wrapper = mount(VanImage, { + propsData: { + src: 'https://img.yzcdn.cn/vant/cat.jpeg', + }, + scopedSlots: { + default: () => 'Custom Default', + }, + }); + + expect(wrapper).toMatchSnapshot(); +});