vue—input上传图片,视频,文件
<input type="file" @change="changePic(item.id)" class="pfile-btn" ref="imgFile" />
return{
//声明存储图片的变量
picList: [{ id: 0, url: "static/image/add1.png", doc: "" }],
}
changePic(id) {
let that=this;
const file = that.$refs.imgFile[id].files;
var myimg=URL.createObjectURL(file[0])
var img=new Image();
img.src=myimg;
img.οnlοad=function(){
console.log(img.height)
if(img.width==340||img.height==100){ //判断文件宽高
that.upLoadImgFunc(file[0], id);
}else{
Dialog.alert({
message:'请上传340*100尺寸的图片'
})
}
}
},
upLoadImgFunc(files, i) {
let param = new FormData();
param.append("file[]", files);
param.append("_token", this.token);
param.append("_client_type", 2);
this.instance
.post("demo接口", param)
.then((res) => {
if (res.data.code == 1) {
this.picList[i].url = res.data.data["0"].url.old_img;
}
});
},