let files = this.filePicker.files;
if(!files.length) {
return;
}
let arr = [];
for(let i = 0, len = files.length; i < len; i++) {
let item = files[i];
// 每个文件初始进度为0
item.progress = '0';
arr.push(obj);
}
this.fileArr = arr;
// 用数组模拟 files, 用对象模拟 file 对象
let files = [];
for(let i = 0, len = 5; i < len; i++) {
let obj = {name: 'name_' + 1};
files.push(obj);
}
let arr = [];
for(let i = 0, len = files.length; i < len; i++) {
files[i].progress = '0';
arr.push(files[i]);
}
let files = this.filePicker.files;
if(!files.length) {
return;
}
let arr = [];
for(let i = 0, len = files.length; i < len; i++) {
let item = files[i];
let obj = {};
obj.name = item.name;
obj.size = item.size;
obj.progress = '0';
arr.push(obj);
}
console.log('files type', Object.prototype.toString.call(files));
// files type [object FileList]
console.log('arr type', Object.prototype.toString.call(arr));
// arr type [object Array]
console.log('item type', Object.prototype.toString.call (files[0]));
// item type [object File]
console.log('obj type', Object.prototype.toString.call (obj));
// obj type [object Object]
<div id="app">
<input type="text" id='a'>
<span id='b'></span>
<input type="file" id='file'>
<button type="button" id='button'>点击更改file属性</button>
</div>
<script>
// 普通对象设置 setter
var obj = {};
Object.defineProperty(obj, 'hello', {
set: function(newVal) {
document.getElementById('a').value = newVal;
document.getElementById('b').innerHTML = newVal;
}
});
document.addEventListener('keyup', function(e){
obj.hello = e.target.value;
});
// File 对象设置 setter
var fileInput = document.getElementById('file');
var file;
fileInput.addEventListener('change', function(e){
file = fileInput.files[0];
Object.defineProperty(file, 'progress', {
set: function(newVal) {
// document.getElementById('a').value = newVal;
document.getElementById('b').innerHTML = newVal;
}
});
});
document.getElementById('button').addEventListener('click', function(){
file.progress = 'hello file';
});
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有