Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
||
* 移除并销毁loading
|
||
* 放在这里是而不是放在 index.html 的app标签内,是因为这样比较不会生硬,渲染过快可能会有闪烁
|
||
* 通过先添加css动画隐藏,在动画结束后在移除loading节点来改善体验
|
||
* 不好的地方是会增加一些代码量
|
||
* 自定义loading可以见:https://doc.vben.pro/guide/in-depth/loading.html
|
||
*/
|
||
export function unmountGlobalLoading() {
|
||
// 查找全局 loading 元素
|
||
const loadingElement = document.querySelector('#__app-loading__');
|
||
|
||
if (loadingElement) {
|
||
// 添加隐藏类,触发过渡动画
|
||
loadingElement.classList.add('hidden');
|
||
|
||
// 查找所有需要移除的注入 loading 元素
|
||
const injectLoadingElements = document.querySelectorAll(
|
||
'[data-app-loading^="inject"]',
|
||
);
|
||
|
||
// 当过渡动画结束时,移除 loading 元素和所有注入的 loading 元素
|
||
loadingElement.addEventListener(
|
||
'transitionend',
|
||
() => {
|
||
loadingElement.remove(); // 移除 loading 元素
|
||
injectLoadingElements.forEach((el) => el.remove()); // 移除所有注入的 loading 元素
|
||
},
|
||
{ once: true },
|
||
); // 确保事件只触发一次
|
||
}
|
||
}
|