File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed
Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ export function useRequest<T = any>(
189189 } ;
190190
191191 // 解决 uni.request complete 未触发问题
192- const completeOnce = once ( ( r ) => {
192+ const complete = once ( ( r ) => {
193193 _config . complete ?.( r ) ;
194194 onFinish ( r ) ;
195195 if ( currentExecuteCounter === executeCounter ) {
@@ -209,18 +209,16 @@ export function useRequest<T = any>(
209209 data . value = result ;
210210 onSuccess ( result ) ;
211211
212- completeOnce ( r ) ;
212+ complete ( r ) ;
213213 } ,
214214 fail : ( e ) => {
215215 _config . fail ?.( e ) ;
216216 error . value = e ;
217217 onError ( e ) ;
218218
219- completeOnce ( e ) ;
220- } ,
221- complete : ( r ) => {
222- completeOnce ( r ) ;
219+ complete ( e ) ;
223220 } ,
221+ complete,
224222 } ) ;
225223 return promise ;
226224 } ) as OverallUseRequestReturn < T > [ 'execute' ] ;
Original file line number Diff line number Diff line change @@ -125,14 +125,14 @@ export function isThenable(promise: any) {
125125 * @param fn 需要包装的原始函数
126126 * @returns 返回一个新的函数,该函数只会执行一次原始函数,后续调用将返回第一次执行的结果
127127 */
128- export function once < F extends ( ...args : any [ ] ) => any > ( fn : F ) : F {
128+ export function once < F extends ( ...args : any [ ] ) => any > ( fn : F , ctx : unknown = null ) : F {
129129 let res : any ;
130130 let f : typeof fn | undefined = fn ;
131131
132132 // 返回包装后的函数,确保原始函数只执行一次
133133 return ( ( ...args ) => {
134134 if ( f ) {
135- res = f ( ... args ) ;
135+ res = f . apply ( ctx , args ) ;
136136 f = undefined ; // 执行一次就设为 undefined
137137 }
138138 return res ;
You can’t perform that action at this time.
0 commit comments