Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
web-framework-temp
/
vue-cli3-vt-template-master
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2a145a18
authored
2022-09-01 15:45:30 +0800
by
simon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1、路由兼容name写法
2、utils修复防抖/节流函数
1 parent
4d62f5c3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
src/utils/utils.js
src/utils/utils.js
View file @
2a145a1
...
...
@@ -199,46 +199,52 @@ export function formatDate(date, fmt) {
/**
* @desc 函数防抖
* @param func 函数
* @param wait 延迟执行毫秒数
* @param immediate true 表立即执行,false 表非立即执行
*/
export
function
debounce
(
func
,
wait
,
immediate
)
{
let
timeout
;
let
debounceTimeout
;
export
function
debounce
(
func
,
wait
,
immediate
)
{
return
function
()
{
let
context
=
this
;
let
args
=
arguments
;
if
(
timeout
)
clearTimeout
(
t
imeout
);
if
(
debounceTimeout
)
clearTimeout
(
debounceT
imeout
);
if
(
immediate
)
{
var
callNow
=
!
t
imeout
;
t
imeout
=
setTimeout
(()
=>
{
t
imeout
=
null
;
var
callNow
=
!
debounceT
imeout
;
debounceT
imeout
=
setTimeout
(()
=>
{
debounceT
imeout
=
null
;
},
wait
)
if
(
callNow
)
func
.
apply
(
context
,
args
)
}
else
{
t
imeout
=
setTimeout
(
function
()
{
debounceT
imeout
=
setTimeout
(
function
()
{
func
.
apply
(
context
,
args
)
},
wait
);
}
}();
}
}
/**
/**
* @desc 函数节流
* @param func 函数
* @param wait 延迟执行毫秒数
* @param type 1 表时间戳版,2 表定时器版
* 时间戳版的函数触发是在时间段内开始的时候,而定时器版的函数触发是在时间段内结束的时候。
*/
export
function
throttle
(
func
,
wait
,
type
)
{
let
throttleTimeout
;
let
throttlePrevious
;
export
function
throttle
(
func
,
wait
,
type
)
{
if
(
type
===
1
)
{
var
p
revious
=
0
;
throttleP
revious
=
0
;
}
else
if
(
type
===
2
)
{
var
timeout
;
throttleTimeout
=
0
;
}
return
function
()
{
let
context
=
this
;
...
...
@@ -246,17 +252,18 @@ export function throttle(func, wait, type) {
if
(
type
===
1
)
{
let
now
=
Date
.
now
();
if
(
now
-
p
revious
>
wait
)
{
if
(
now
-
throttleP
revious
>
wait
)
{
func
.
apply
(
context
,
args
);
p
revious
=
now
;
throttleP
revious
=
now
;
}
}
else
if
(
type
===
2
)
{
if
(
!
t
imeout
)
{
t
imeout
=
setTimeout
(()
=>
{
t
imeout
=
null
;
if
(
!
throttleT
imeout
)
{
throttleT
imeout
=
setTimeout
(()
=>
{
throttleT
imeout
=
null
;
func
.
apply
(
context
,
args
)
},
wait
)
}
}
}();
}
}
\ No newline at end of file
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment