diff --git a/src/notice-bar/README.md b/src/notice-bar/README.md index 0a10f1ee2..5a481ca50 100644 --- a/src/notice-bar/README.md +++ b/src/notice-bar/README.md @@ -79,8 +79,8 @@ Vue.use(NoticeBar); | Event | Description | Arguments | |------|------|------| -| click | Triggered when click NoticeBar | - | -| close | Triggered when closed | - | +| click | Triggered when click NoticeBar | event: Event | +| close | Triggered when closed | event: Event | ### Slots diff --git a/src/notice-bar/README.zh-CN.md b/src/notice-bar/README.zh-CN.md index 4a6aa52ce..205dbe6ff 100644 --- a/src/notice-bar/README.zh-CN.md +++ b/src/notice-bar/README.zh-CN.md @@ -87,8 +87,8 @@ Vue.use(NoticeBar); | 事件名 | 说明 | 回调参数 | |------|------|------| -| click | 点击通知栏时触发 | - | -| close | 关闭通知栏时触发 | - | +| click | 点击通知栏时触发 | event: Event | +| close | 关闭通知栏时触发 | event: Event | ### Slots diff --git a/src/notice-bar/index.js b/src/notice-bar/index.js index a7e843a55..36661281b 100644 --- a/src/notice-bar/index.js +++ b/src/notice-bar/index.js @@ -60,10 +60,10 @@ export default createComponent({ }, methods: { - onClickIcon() { + onClickIcon(event) { if (this.mode === 'closeable') { this.showNoticeBar = false; - this.$emit('close'); + this.$emit('close', event); } }, @@ -121,8 +121,8 @@ export default createComponent({ vShow={this.showNoticeBar} class={bem({ wrapable: this.wrapable })} style={barStyle} - onClick={() => { - this.$emit('click'); + onClick={event => { + this.$emit('click', event); }} > {LeftIcon()} diff --git a/src/notice-bar/test/index.spec.js b/src/notice-bar/test/index.spec.js index df1b7a133..8c5a680f1 100644 --- a/src/notice-bar/test/index.spec.js +++ b/src/notice-bar/test/index.spec.js @@ -1,6 +1,13 @@ import NoticeBar from '..'; import { mount } from '../../../test/utils'; +test('click event', () => { + const wrapper = mount(NoticeBar); + + wrapper.trigger('click'); + expect(wrapper.emitted('click')[0][0]).toBeTruthy(); +}); + test('close event', () => { const wrapper = mount(NoticeBar, { propsData: { @@ -10,7 +17,7 @@ test('close event', () => { const close = wrapper.find('.van-notice-bar__right-icon'); close.trigger('click'); - expect(wrapper.emitted('close')).toBeTruthy(); + expect(wrapper.emitted('close')[0][0]).toBeTruthy(); }); test('icon slot', () => {