From 5b4a4cc07887f41d87d82ac51d3b744e39a79209 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 2 Jul 2019 14:04:55 +0800 Subject: [PATCH] [bugfix] PullRefresh: ensure value change can be watched (#3719) --- src/pull-refresh/index.js | 7 ++++++- src/pull-refresh/test/index.spec.js | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pull-refresh/index.js b/src/pull-refresh/index.js index 1b22c47f5..db6a58caf 100644 --- a/src/pull-refresh/index.js +++ b/src/pull-refresh/index.js @@ -99,10 +99,15 @@ export default createComponent({ onTouchEnd() { if (!this.untouchable && this.ceiling && this.deltaY) { this.duration = this.animationDuration; + if (this.status === 'loosing') { this.setStatus(this.headHeight, true); this.$emit('input', true); - this.$emit('refresh'); + + // ensure value change can be watched + this.$nextTick(() => { + this.$emit('refresh'); + }); } else { this.setStatus(0); } diff --git a/src/pull-refresh/test/index.spec.js b/src/pull-refresh/test/index.spec.js index bcdeeb1e5..12bba11a6 100644 --- a/src/pull-refresh/test/index.spec.js +++ b/src/pull-refresh/test/index.spec.js @@ -1,7 +1,7 @@ import PullRefresh from '..'; -import { mount, trigger, triggerDrag } from '../../../test/utils'; +import { mount, later, trigger, triggerDrag } from '../../../test/utils'; -test('change head content when pulling down', () => { +test('change head content when pulling down', async () => { const wrapper = mount(PullRefresh, { propsData: { value: false @@ -32,6 +32,9 @@ test('change head content when pulling down', () => { expect(wrapper).toMatchSnapshot(); expect(wrapper.emitted('input')).toBeTruthy(); + expect(wrapper.emitted('refresh')).toBeFalsy(); + + await later(); expect(wrapper.emitted('refresh')).toBeTruthy(); // end loading