生活随笔
收集整理的這篇文章主要介紹了
Vue+mui实现图片的本地缓存
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果:
const menu = {state: {products: {},GLOBAL_CONFIG:GLOBAL_CONFIG[
'GLOBAL_CONFIG']},mutations: {get_product:
function (state, products) {state.products = products;
for(
let i =
0; i < state.products.length; i++){
if(state.products[i][
'image'] !=
null){
this.commit(
'imgCache',state.products[i]);}
else{state.products[i][
'image'] =
require(
"../assets/file.png");}}},imgCache:
function (state,imgObj) {mui.plusReady(
function(){let image_url = imgObj.image;
let image_md5 = md5(image_url);
let local_image_url =
'_downloads/image/'+image_md5+
'.jpg';
let absolute_image_path = plus.io.convertLocalFileSystemURL(local_image_url);console.log(absolute_image_path);plus.io.resolveLocalFileSystemURL( absolute_image_path,
function( entry ) {if(entry){imgObj.image = plus.io.convertLocalFileSystemURL(local_image_url);}
else{download_img();}},
function ( e ) {console.log(
"Resolve file URL failed: ");download_img();} );
function download_img(){let download_task = plus.downloader.createDownload(image_url, {filename: local_image_url},
function(download, status) {if(status !=
200){console.log(
'下載失敗,status'+status);
if(local_image_url !=
null){plus.io.resolveLocalFileSystemURL(local_image_url,
function(entry) {entry.remove(
function(entry) {console.log(
"臨時文件刪除成功" + local_image_url);download_img();},
function(e) {console.log(
"臨時文件刪除失敗" + local_image_url);});});}}
else{console.log(
"下載成功" + local_image_url);imgObj.image = plus.io.convertLocalFileSystemURL(local_image_url);}});download_task.start();} });}},actions: {}
}
總結
以上是生活随笔為你收集整理的Vue+mui实现图片的本地缓存的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。