generated from nuxt/nuxt_site
31 lines
666 B
JavaScript
31 lines
666 B
JavaScript
/**
|
|
* 防抖函数
|
|
* @param {*} fn 回调函数
|
|
* @param {*} delay 延迟时间
|
|
* @returns
|
|
*/
|
|
export const debounce = (fn, delay) => {
|
|
let timer = null;
|
|
return function () {
|
|
if (timer) {
|
|
clearTimeout(timer);
|
|
}
|
|
timer = setTimeout(() => {
|
|
fn.apply(this, arguments);
|
|
}, delay);
|
|
}
|
|
}
|
|
|
|
export const isWechat = () => {
|
|
return /MicroMessenger/i.test(window.navigator.userAgent);
|
|
}
|
|
|
|
export const getHerf = (url = undefined) => {
|
|
if (url) {
|
|
const {locale} = useI18n()
|
|
if (locale.value !== 'en') {
|
|
url = '/' + locale.value + (url);
|
|
}
|
|
return url
|
|
}
|
|
} |