我创建了一个应用程序并且它确实很有效,但每次我上下滚动时图像都会加载,我在谷歌中找到它并找到this,问题是我使用了角度,没有{{ {1}}在我的角度版本中,如何将缓存图像应用到模板中?
答案 0 :(得分:1)
You can try this code. It is working for me.
.ts code
import imageCacheModule = require("ui/image-cache");
import imageSource = require("image-source");
var cache = new imageCacheModule.Cache();
private _imageSrc: any;
private imgSource: any;
getImageCache(imageURL) {
cache.placeholder = imageSource.fromResource("res://no-image.png");
cache.maxRequests = 10;
cache.enableDownload()
var images = cache.get(imageURL)
if(images) {
return images
} else {
cache.push({
key: imageURL,
url: imageURL,
completed: (image: any, key: string) => {
if (imageURL === key) {
this.imgSource = imageSource.fromNativeSource(images);
}
}
})
cache.disableDownload();
}
HTMl code
<Image [src]="getImageCache(item.image?.url)" class="item-image"></Image>