美文网首页
vue上传图片

vue上传图片

作者: 2359634711 | 来源:发表于2019-08-14 09:50 被阅读0次
    
    add_img(event){  
                let reader =new FileReader();
                let img1=event.target.files[0];
                let type=img1.type;//文件的类型,判断是否是图片
                let size=img1.size;//文件的大小,判断图片的大小
                if(this.imgData.accept.indexOf(type) == -1){
                    alert('请选择我们支持的图片格式!');
                    return false;
                }
                if(size>3145728){
                    alert('请选择3M以内的图片!');
                    return false;
                }
                var uri = ''
                let form = new FormData(); 
                form.append('file',img1,img1.name);
                this.$http.post('/file/upload',form,{
                    headers:{'Content-Type':'multipart/form-data'}
                }).then(response => {
                    console.log(response.data)
                    uri = response.data.url
                    reader.readAsDataURL(img1);
                    var that=this;
                    reader.onloadend=function(){
                        that.imgs.push(uri);
                    }
                }).catch(error => {
                    alert('上传图片出错!');
                })    
    }
    --------------------- 
    版权声明:本文为CSDN博主「小雷雷哥哥」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/leileibrother/article/details/79020758
    

    相关文章

      网友评论

          本文标题:vue上传图片

          本文链接:https://www.haomeiwen.com/subject/povwjctx.html