Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
tswj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2022-05-28 22:57:58 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ab19e885e2b78813cd1f7565cd642cb9d475949f
ab19e885
1 parent
21e1783c
✨ feat: 简单封装debounce防抖函数
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
src/components/VideoCard/index.vue
src/hooks/useDebounce.js
src/components/VideoCard/index.vue
View file @
ab19e88
...
...
@@ -5,9 +5,8 @@
<div class="video-bar">
<van-row>
<van-col span="12" @click="goTo">
<van-image v-if="item.avatar" round width="2rem" height="2rem" style="vertical-align: middle;" :src="item.avatar" />
<van-image v-else round width="2rem" height="2rem" style="vertical-align: middle;" :src="icon_avatar" />
<span style="font-size: 1.05rem;vertical-align: middle;">{{ item.name }}</span>
<van-image round width="2rem" height="2rem" style="vertical-align: middle;" :src="item.avatar ? item.avatar : icon_avatar" />
<span style="font-size: 1.05rem;vertical-align: middle; display: inline-block; padding-left: 1rem;">{{ item.name }}</span>
</van-col>
<van-col span="12">
<div style="padding: 0.25rem; padding-top: 0.75rem; text-align: right;">
...
...
@@ -42,11 +41,15 @@ import { useRouter } from 'vue-router'
import 'mui-player/dist/mui-player.min.css'
import MuiPlayer from 'mui-player'
import { prodActionAPI, prodInfoAPI } from '@/api/C/prod.js'
import { useDebounce } from '@/hooks/useDebounce.js'
const $router = useRouter();
const props = defineProps({
item: {
type: Object,
default(rawProps) {
return rawProps
}
}
})
...
...
@@ -55,7 +58,7 @@ const props = defineProps({
* 两个请求顺序执行,处理直接写在请求函数里面似乎有点问题,get请求数据似乎无法顺利渲染显示
*/
// FIXME:防抖处理
const handleAction =
_.d
ebounce(async (action_type, prod_id) => {
const handleAction =
useD
ebounce(async (action_type, prod_id) => {
const { msg } = await prodActionAPI({ action_type, prod_id });
if (msg === `${action_type}-add-OK`) { // 动作操作成功
if (action_type === 'favor') {
...
...
@@ -70,7 +73,7 @@ const handleAction = _.debounce(async (action_type, prod_id) => {
}
}
getProductDetail(action_type, prod_id); // 更新信息
}
, 500, { leading: true, trailing: false }
);
});
// 查询作品详情
const getProductDetail = async (action_type, prod_id) => {
...
...
@@ -142,7 +145,6 @@ const setComment = () => {
color: #713610;
padding: 1rem;
padding-bottom: 0.5rem;
}
}
</style>
...
...
src/hooks/useDebounce.js
0 → 100644
View file @
ab19e88
import
_
from
'lodash'
;
/**
* 封装lodash防抖
* @param {*} fn 执行函数
* @param {*} timestamp 执行间隔
* @param {*} options 函数配置 - 在延迟开始前调用,在延迟结束后不调用
* @returns 返回新的 debounced(防抖动)函数。
*/
export
const
useDebounce
=
(
fn
,
timestamp
=
500
,
options
=
{
leading
:
true
,
trailing
:
false
})
=>
{
return
_
.
debounce
(
fn
,
timestamp
,
options
);
}
Please
register
or
login
to post a comment