文章詳情頁
html5 - input type=’file’ 上傳獲取的fileList對象怎么存儲于瀏覽器?
瀏覽:200日期:2022-12-13 14:04:07
問題描述
let files = e.target.files;localStorage.setItem(’files’,JSON.stringify(files));存儲結(jié)果是:{'0':{}}怎么解決,在線等......
問題解答
回答1:e.target.files 不是數(shù)組,所以需要轉(zhuǎn)換成數(shù)組。
Array.from
數(shù)據(jù)的每一項(xiàng)都是一個(gè) File 對象,如果你想存儲文件名,可以取 name 屬性。
代碼大概是這樣的:
let files = Array.from(e.target.files).map(x => x.name);localStorage.setItem(’files’,JSON.stringify(files));
或者
let files = [...e.target.files].map(x => x.name);localStorage.setItem(’files’,JSON.stringify(files));
標(biāo)簽:
Html5
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. docker-compose中volumes的問題3. boot2docker無法啟動4. nignx - docker內(nèi)nginx 80端口被占用5. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.6. docker容器呢SSH為什么連不通呢?7. node.js - antdesign怎么集合react-redux對input控件進(jìn)行初始化賦值8. dockerfile - 為什么docker容器啟動不了?9. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類10. 關(guān)于docker下的nginx壓力測試
排行榜

熱門標(biāo)簽
網(wǎng)公網(wǎng)安備