Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 异步加载文件成功提示信息 #32

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const asyncLoadJs = (() => {
// 正在加载或已经加载成功的,直接返回
if (loaded.get(url)) return loaded.get(url);

const load = new Promise<void>((resolve, reject) => {
const load = new Promise((resolve, reject) => {
const script = document.createElement("script");
script.type = "text/javascript";
if (crossOrigin) {
Expand All @@ -24,7 +24,7 @@ export const asyncLoadJs = (() => {
script.src = url;
document.body.appendChild(script);
script.onload = () => {
resolve();
resolve({ msg: "加载成功", url });
};
script.onerror = () => {
reject(new Error("加载失败"));
Expand Down Expand Up @@ -60,13 +60,13 @@ export const asyncLoadCss = (() => {
// 正在加载或已经加载成功的,直接返回
if (loaded.get(url)) return loaded.get(url);

const load = new Promise<void>((resolve, reject) => {
const load = new Promise((resolve, reject) => {
const node = document.createElement("link");
node.rel = "stylesheet";
node.href = url;
document.head.appendChild(node);
node.onload = () => {
resolve();
resolve({ msg: "加载成功", url });
};
node.onerror = () => {
reject(new Error("加载失败"));
Expand Down