<input type="file" id="file"
style="width:70px;margin-top:22px;"
accept="image/jpeg,image/jpg,image/png"
@change="getPicshop($event)" />
//这是input框
getPicshop(e) {
console.log(e)
const files = e.target.files[0]
let formData = new FormData()
formData.append('file', files)
post({
api: api.uploadImg,//上传图片的接口
data: formData
}).then((res) => {
console.log(res.data.data.url)
let img = res.data.data.url
let imgObj = new Image()
imgObj.src = img
let that = this
imgObj.onload = function () {
console.log('width:' + imgObj.width + ',height:' + imgObj.height);
if (imgObj.width > 240 && imgObj.width < 512 && imgObj.height > 240
&& imgObj.height < 512) {//这是判断,没有条件可以不判断
that.logoimg = res.data.data.url
let logo = {
shopLogo: that.logoimg
}
that.saveLogo(logo)
} else {
alert('请上传大于240*240px小于512*512的图片')
return
}
};
})
},
input 上传文件或者图片
最新推荐文章于 2024-07-25 10:33:27 发布