Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 97bf89b

Browse files
committed
fix: 修复prop config的无法覆盖的bug
1 parent 069dc7d commit 97bf89b

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

src/utils.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
export function extend (target, source) {
2-
for (let key in source) {
3-
target[key] = source[key];
4-
}
5-
}
6-
71
// http://www.alloyteam.com/2012/11/javascript-throttle/
82
export function throttle (fn, delay) {
93
let timer = null;

src/vue-pull-to.vue

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</template>
2727

2828
<script type="text/babel">
29-
import {extend, throttle, throttleRunDelay} from './utils';
29+
import {throttle, throttleRunDelay} from './utils';
3030
import {TOP_DEFAULT_CONFIG, BOTTOM_DEFAULT_CONFIG} from './config';
3131
3232
export default {
@@ -57,21 +57,13 @@
5757
topConfig: {
5858
type: Object,
5959
default: () => {
60-
return TOP_DEFAULT_CONFIG;
61-
},
62-
validator: (config) => {
63-
extend(config, TOP_DEFAULT_CONFIG);
64-
return config;
60+
return {};
6561
}
6662
},
6763
bottomConfig: {
6864
type: Object,
6965
default: () => {
70-
return BOTTOM_DEFAULT_CONFIG;
71-
},
72-
validator: (config) => {
73-
extend(config, BOTTOM_DEFAULT_CONFIG);
74-
return config;
66+
return {};
7567
}
7668
}
7769
},
@@ -91,6 +83,14 @@
9183
bottomReached: false
9284
};
9385
},
86+
computed: {
87+
_topConfig: function () {
88+
return Object.assign(TOP_DEFAULT_CONFIG, this.topConfig);
89+
},
90+
_bottomConfig: function () {
91+
return Object.assign(BOTTOM_DEFAULT_CONFIG, this.bottomConfig);
92+
}
93+
},
9494
watch: {
9595
state(val) {
9696
if (this.direction === 'down') {
@@ -104,41 +104,41 @@
104104
actionPull() {
105105
this.state = 'pull';
106106
this.direction === 'down'
107-
? this.topText = this.topConfig.pullText
108-
: this.bottomText = this.bottomConfig.pullText;
107+
? this.topText = this._topConfig.pullText
108+
: this.bottomText = this._bottomConfig.pullText;
109109
},
110110
actionTrigger() {
111111
this.state = 'trigger';
112112
this.direction === 'down'
113-
? this.topText = this.topConfig.triggerText
114-
: this.bottomText = this.bottomConfig.triggerText;
113+
? this.topText = this._topConfig.triggerText
114+
: this.bottomText = this._bottomConfig.triggerText;
115115
},
116116
actionLoading() {
117117
this.state = 'loading';
118118
if (this.direction === 'down') {
119-
this.topText = this.topConfig.loadingText;
119+
this.topText = this._topConfig.loadingText;
120120
/* eslint-disable no-useless-call */
121121
this.topLoadMethod.call(this, this.actionLoaded);
122-
this.scrollTo(this.topConfig.stayDistance);
122+
this.scrollTo(this._topConfig.stayDistance);
123123
} else {
124-
this.bottomText = this.bottomConfig.loadingText;
124+
this.bottomText = this._bottomConfig.loadingText;
125125
this.bottomLoadMethod.call(this, this.actionLoaded);
126-
this.scrollTo(-this.bottomConfig.stayDistance);
126+
this.scrollTo(-this._bottomConfig.stayDistance);
127127
}
128128
},
129129
actionLoaded(loadState = 'done') {
130130
this.state = `loaded-${loadState}`;
131131
let loadedStayTime;
132132
if (this.direction === 'down') {
133133
this.topText = loadState === 'done'
134-
? this.topConfig.doneText
135-
: this.topConfig.failText;
136-
loadedStayTime = this.topConfig.loadedStayTime;
134+
? this._topConfig.doneText
135+
: this._topConfig.failText;
136+
loadedStayTime = this._topConfig.loadedStayTime;
137137
} else {
138138
this.bottomText = loadState === 'done'
139-
? this.bottomConfig.doneText
140-
: this.bottomConfig.failText;
141-
loadedStayTime = this.bottomConfig.loadedStayTime;
139+
? this._bottomConfig.doneText
140+
: this._bottomConfig.failText;
141+
loadedStayTime = this._bottomConfig.loadedStayTime;
142142
}
143143
setTimeout(() => {
144144
this.scrollTo(0);
@@ -184,10 +184,10 @@
184184
185185
if (typeof this.topLoadMethod !== 'function') return;
186186
187-
if (this.distance < this.topConfig.triggerDistance &&
187+
if (this.distance < this._topConfig.triggerDistance &&
188188
this.state !== 'pull' && this.state !== 'loading') {
189189
this.actionPull();
190-
} else if (this.distance >= this.topConfig.triggerDistance &&
190+
} else if (this.distance >= this._topConfig.triggerDistance &&
191191
this.state !== 'trigger' && this.state !== 'loading') {
192192
this.actionTrigger();
193193
}
@@ -199,10 +199,10 @@
199199
200200
if (typeof this.bottomLoadMethod !== 'function') return;
201201
202-
if (Math.abs(this.distance) < this.bottomConfig.triggerDistance &&
202+
if (Math.abs(this.distance) < this._bottomConfig.triggerDistance &&
203203
this.state !== 'pull' && this.state !== 'loading') {
204204
this.actionPull();
205-
} else if (Math.abs(this.distance) >= this.bottomConfig.triggerDistance &&
205+
} else if (Math.abs(this.distance) >= this._bottomConfig.triggerDistance &&
206206
this.state !== 'trigger' && this.state !== 'loading') {
207207
this.actionTrigger();
208208
}

0 commit comments

Comments
 (0)