From e95e09764ad8498760d447df8b58027c5743c8f0 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 17 Apr 2020 21:34:02 +0800 Subject: [PATCH] feat(NoticeBar): add replay event (#6079) --- src/notice-bar/README.md | 9 +++++---- src/notice-bar/README.zh-CN.md | 9 +++++---- src/notice-bar/index.js | 1 + src/notice-bar/test/index.spec.js | 14 +++++++++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/notice-bar/README.md b/src/notice-bar/README.md index 78db45215..bcf2c72ad 100644 --- a/src/notice-bar/README.md +++ b/src/notice-bar/README.md @@ -71,10 +71,11 @@ Vue.use(NoticeBar); ### Events -| Event | Description | Arguments | -| ----- | ------------------------------ | -------------- | -| click | Triggered when click NoticeBar | _event: Event_ | -| close | Triggered when closed | _event: Event_ | +| Event | Description | Arguments | +| --------------- | ------------------------------ | -------------- | +| click | Triggered when click NoticeBar | _event: Event_ | +| close | Triggered when closed | _event: Event_ | +| replay `v2.6.2` | Triggered when replay | - | ### Slots diff --git a/src/notice-bar/README.zh-CN.md b/src/notice-bar/README.zh-CN.md index 2f3f1f28a..1dc2f4d26 100644 --- a/src/notice-bar/README.zh-CN.md +++ b/src/notice-bar/README.zh-CN.md @@ -79,10 +79,11 @@ Vue.use(NoticeBar); ### Events -| 事件名 | 说明 | 回调参数 | -| ------ | ---------------- | -------------- | -| click | 点击通知栏时触发 | _event: Event_ | -| close | 关闭通知栏时触发 | _event: Event_ | +| 事件名 | 说明 | 回调参数 | +| --------------- | ---------------------------- | -------------- | +| click | 点击通知栏时触发 | _event: Event_ | +| close | 关闭通知栏时触发 | _event: Event_ | +| replay `v2.6.2` | 每当滚动栏重新开始滚动时触发 | - | ### Slots diff --git a/src/notice-bar/index.js b/src/notice-bar/index.js index 0920bf2bd..be5b51ccf 100644 --- a/src/notice-bar/index.js +++ b/src/notice-bar/index.js @@ -72,6 +72,7 @@ export default createComponent({ this.$nextTick(() => { this.duration = (this.offsetWidth + this.wrapWidth) / this.speed; this.animationClass = bem('play--infinite'); + this.$emit('replay'); }); }, }, diff --git a/src/notice-bar/test/index.spec.js b/src/notice-bar/test/index.spec.js index 22bbf5656..8ed91ae0d 100644 --- a/src/notice-bar/test/index.spec.js +++ b/src/notice-bar/test/index.spec.js @@ -1,5 +1,5 @@ import NoticeBar from '..'; -import { mount } from '../../../test'; +import { mount, later } from '../../../test'; test('click event', () => { const wrapper = mount(NoticeBar); @@ -36,3 +36,15 @@ test('icon slot', () => { expect(wrapper).toMatchSnapshot(); }); + +test('replay event', async () => { + const wrapper = mount(NoticeBar, { + propsData: { + text: 'foo', + }, + }); + + wrapper.find('.van-notice-bar__content').trigger('animationend'); + await later(); + expect(wrapper.emitted('replay')).toBeTruthy(); +});