From bb8a3d60b7d095fcd4c6df31b7c3d5a89cb12354 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sat, 25 Jul 2020 22:21:22 +0800 Subject: [PATCH] feat: migrate PullRefresh component --- components.js | 1 + src/pull-refresh/index.js | 21 ++++++++++++--------- vant.config.js | 16 ++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components.js b/components.js index bdfdccaeb..3a1c30441 100644 --- a/components.js +++ b/components.js @@ -34,4 +34,5 @@ module.exports = [ 'tree-select', 'notice-bar', 'share-sheet', + 'pull-refresh', ]; diff --git a/src/pull-refresh/index.js b/src/pull-refresh/index.js index 776017e71..f498925b4 100644 --- a/src/pull-refresh/index.js +++ b/src/pull-refresh/index.js @@ -23,7 +23,7 @@ export default createComponent({ pullingText: String, loosingText: String, loadingText: String, - value: { + modelValue: { type: Boolean, required: true, }, @@ -41,6 +41,8 @@ export default createComponent({ }, }, + emits: ['refresh', 'update:modelValue'], + data() { return { status: 'normal', @@ -66,12 +68,14 @@ export default createComponent({ }, watch: { - value(loading) { + modelValue(loading) { this.duration = this.animationDuration; if (loading) { this.setStatus(+this.headHeight, true); - } else if (this.slots('success') || this.successText) { + } else if ( + this.$slots.success ? this.$slots.success() : this.successText + ) { this.showSuccessTip(); } else { this.setStatus(0, false); @@ -123,7 +127,7 @@ export default createComponent({ if (this.status === 'loosing') { this.setStatus(+this.headHeight, true); - this.$emit('input', true); + this.$emit('update:modelValue', true); // ensure value change can be watched this.$nextTick(() => { @@ -168,14 +172,13 @@ export default createComponent({ genStatus() { const { status, distance } = this; - const slot = this.slots(status, { distance }); - if (slot) { - return slot; + if (this.$slots[status]) { + return this.$slots[status]({ distance }); } const nodes = []; - const text = this[`${status}Text`] || t(status); + const text = (status !== 'normal' && this[`${status}Text`]) || t(status); if (TEXT_STATUS.indexOf(status) !== -1) { nodes.push(
{text}
); @@ -209,7 +212,7 @@ export default createComponent({
{this.genStatus()}
- {this.slots()} + {this.$slots.default?.()} ); diff --git a/vant.config.js b/vant.config.js index 3fe9e0859..e450f329e 100644 --- a/vant.config.js +++ b/vant.config.js @@ -204,10 +204,10 @@ module.exports = { path: 'overlay', title: 'Overlay 遮罩层', }, - // { - // path: 'pull-refresh', - // title: 'PullRefresh 下拉刷新', - // }, + { + path: 'pull-refresh', + title: 'PullRefresh 下拉刷新', + }, { path: 'share-sheet', title: 'ShareSheet 分享面板', @@ -538,10 +538,10 @@ module.exports = { path: 'overlay', title: 'Overlay', }, - // { - // path: 'pull-refresh', - // title: 'PullRefresh', - // }, + { + path: 'pull-refresh', + title: 'PullRefresh', + }, { path: 'share-sheet', title: 'ShareSheet',