[bugfix] PullRefresh: ensure value change can be watched (#3719)

This commit is contained in:
neverland 2019-07-02 14:04:55 +08:00 committed by GitHub
parent 5d5bc878d0
commit 5b4a4cc078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -99,10 +99,15 @@ export default createComponent({
onTouchEnd() { onTouchEnd() {
if (!this.untouchable && this.ceiling && this.deltaY) { if (!this.untouchable && this.ceiling && this.deltaY) {
this.duration = this.animationDuration; this.duration = this.animationDuration;
if (this.status === 'loosing') { if (this.status === 'loosing') {
this.setStatus(this.headHeight, true); this.setStatus(this.headHeight, true);
this.$emit('input', true); this.$emit('input', true);
this.$emit('refresh');
// ensure value change can be watched
this.$nextTick(() => {
this.$emit('refresh');
});
} else { } else {
this.setStatus(0); this.setStatus(0);
} }

View File

@ -1,7 +1,7 @@
import PullRefresh from '..'; 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, { const wrapper = mount(PullRefresh, {
propsData: { propsData: {
value: false value: false
@ -32,6 +32,9 @@ test('change head content when pulling down', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
expect(wrapper.emitted('input')).toBeTruthy(); expect(wrapper.emitted('input')).toBeTruthy();
expect(wrapper.emitted('refresh')).toBeFalsy();
await later();
expect(wrapper.emitted('refresh')).toBeTruthy(); expect(wrapper.emitted('refresh')).toBeTruthy();
// end loading // end loading