0

我正在使用 axios 加载图像,然后将这些图像放在 window.Image() 上。
之后,我在'for'之间使用了onload。
但是当我检查“.then”时,console.log 显示,

hey
0
1
2
3

但是,当我删除“onload”时,console.log 显示,

0
1
2
3
hey


就我而言,我需要 onload 在 image.src 之后运行一些条件。
而且,我需要

0
1
2
3
hey

我该如何解决这种情况?

axios
  .get(`http://localhost:4000//${router.currentRoute.params.id}`)
  .then(payload => {
    if (payload.data) {
      firebaseAuth.onAuthStateChanged(user => {
        for (let i = 0; i < payload.data.works.length; i += 1) {
          const payloadImages = payload.data.works[i];

          const imageYo = new window.Image();
          imageYo.src = payloadImages.imagePath;
          imageYo.onload = () => {
            delete payloadImages._id;

            console.log(i);
          };
        }
      });
    }
  })
  .then(() => {
    console.log('hey');
  });
4

0 回答 0