admin管理员组文章数量:1410717
I have an issue where the image skeleton loader keeps loading infinitely when using the @load
event in Quasar.
const imgLoaded = ref({});
// template
<q-skeleton v-if="!imgLoaded[img?.image_url]"></q-skeleton>
<q-img @load="(url) => imgLoaded[url] = true" :src="img?.image_url" />
The Quasar docs say that @load event is 'Emitted when image has been loaded by the browser. @param src - URL of image that has been loaded'. After the handler sets imgLoaded[url]
to true
, the skeleton should stop showing and the image should be displayed. However, the skeleton keeps loading infinitely.
The same thing is happening with the onload
. Now when I need the image url for img.src
, I take it directly from the store:
// template
<q-skeleton v-if="!imgLoaded[img?.image_url]">
// script
const imgLoaded = ref({});
const onImgLoad = (url) => {
imgLoaded.value[url] = true;
};
onMounted(() => {
if (storeProducts.featuredProducts && storeProducts.featuredProducts.length) {
storeProducts.featuredProducts.forEach((product) => {
const img = new Image();
img.onload = () => onImgLoad(product?.image_url);
img.src = product?.image_url;
});
}
});
However, this approach also causes the skeleton loader to load infinitely.
I've made a reproduction: .vue
Here, none of the imgLoaded[img.image]
is set to true
when the image is loaded. Besides, imgLoaded.value
is initially {}
instead of having each of the object properties set to false
.
I'm looking for a possible solution.
本文标签: javascriptInfinite loading of skeleton loaders with onloadload eventStack Overflow
版权声明:本文标题:javascript - Infinite loading of skeleton loaders with onload@load event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744817614a2626794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论