mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
fix(loginUsername): add throttle for search (#39)
This commit is contained in:
parent
f99dbac95f
commit
af30eb431d
2 changed files with 16 additions and 1 deletions
|
|
@ -58,3 +58,13 @@ export function shuffleAList(list) {
|
||||||
});
|
});
|
||||||
return newSorts;
|
return newSorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function throttle(fn, time) {
|
||||||
|
let isRun = false;
|
||||||
|
return function () {
|
||||||
|
if (isRun) return;
|
||||||
|
isRun = true;
|
||||||
|
fn.apply(this, arguments);
|
||||||
|
setTimeout(() => { isRun = false }, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<input
|
<input
|
||||||
:placeholder="$t('login.searchHolder')"
|
:placeholder="$t('login.searchHolder')"
|
||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
@keydown.enter="search"
|
@keydown.enter="throttleSearch"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -53,6 +53,7 @@ import NProgress from "nprogress";
|
||||||
import { search } from "@/api/others";
|
import { search } from "@/api/others";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { userPlaylist } from "@/api/user";
|
import { userPlaylist } from "@/api/user";
|
||||||
|
import { throttle } from '@/utils/common';
|
||||||
|
|
||||||
import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
|
import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
|
||||||
|
|
||||||
|
|
@ -74,6 +75,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(["updateUser", "updateUserInfo"]),
|
...mapMutations(["updateUser", "updateUserInfo"]),
|
||||||
search() {
|
search() {
|
||||||
|
if (!this.keyword) return;
|
||||||
search({ keywords: this.keyword, limit: 9, type: 1002 }).then((data) => {
|
search({ keywords: this.keyword, limit: 9, type: 1002 }).then((data) => {
|
||||||
this.result = data.result.userprofiles;
|
this.result = data.result.userprofiles;
|
||||||
this.activeUser = this.result[0];
|
this.activeUser = this.result[0];
|
||||||
|
|
@ -93,6 +95,9 @@ export default {
|
||||||
this.$router.push({ path: "/library" });
|
this.$router.push({ path: "/library" });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
throttleSearch: throttle(function () {
|
||||||
|
this.search();
|
||||||
|
}, 500)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue