首页 > 其他分享 >前端Vue图片上传组件支持单个文件多个文件上传 自定义上传数量 预览删除图片 图片压缩

前端Vue图片上传组件支持单个文件多个文件上传 自定义上传数量 预览删除图片 图片压缩

时间:2023-06-19 09:33:40浏览次数:49  
标签:console log 自定义 res progress uni 上传 图片

前端Vue图片上传组件支持单个文件多个文件上传 自定义上传数量 预览删除图片 图片压缩, 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13099

效果图如下:

1.0.0(2023-06-18)

组件初始化

使用方法


<!-- count: 最大上传数量  imageList: 图片上传选择数组-->

<cc-imgPreDelUpload :count="6" :imageList="imgList"></cc-imgPreDelUpload>

<!-- 上传请求事件 -->

goUploadClick() {

if (this.imgList.length < 1) {

uni.showModal({

title: '温馨提示',

content: '请上传图片'

})

return;

}

console.log('图片上传数组 = ' + JSON.stringify(this.imgList));

// 服务器地址上传地址 仅为示例,非真实的接口地址

let baseUrl = "http://gzcc.com/cc//appSc/up"

uni.showLoading({

title: '上传中'

})

const uploadTask = uni.uploadFile({

url: baseUrl, //仅为示例,非真实的接口地址

files: this.imgList, //请求图片数组

formData: {}, //请求参数

success: (uploadFileRes) => {

uni.hideLoading();

console.log('上传成功 = ' + uploadFileRes.data);

}

});

uploadTask.onProgressUpdate((res) => {

if (typeof(res.progress) != String) {

res.progress = '0';

}

// 此处为了模拟上传进度

uni.showLoading({

title: '上传进度: ' + res.progress + '%'

})

console.log('上传进度' + res.progress);

console.log('已经上传的数据长度' + res.totalBytesSent);

console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);

});

}

}

HTML代码部分


<template>

<view class="content">

<!-- count: 最大上传数量  imageList: 图片上传选择数组-->

<cc-imgPreDelUpload :count="6" :imageList="imgList"></cc-imgPreDelUpload>

<button style="width: 120px;background-color: antiquewhite; margin-top: 60px;" @click="goUploadClick"> 上传

</button>

</view>

</template>

<script>

export default {

data() {

return {

imgList: []

}

},

methods: {

goUploadClick() {

if (this.imgList.length < 1) {

uni.showModal({

title: '温馨提示',

content: '请上传图片'

})

return;

}

console.log('图片上传数组 = ' + JSON.stringify(this.imgList));

// 服务器地址上传地址 仅为示例,非真实的接口地址

let baseUrl = "http://gzcc.com/cc//appSc/up"

uni.showLoading({

title: '上传中'

})

const uploadTask = uni.uploadFile({

url: baseUrl, //仅为示例,非真实的接口地址

files: this.imgList, //请求图片数组

formData: {}, //请求参数

success: (uploadFileRes) => {

uni.hideLoading();

console.log('上传成功 = ' + uploadFileRes.data);

}

});

uploadTask.onProgressUpdate((res) => {

if (typeof(res.progress) != String) {

res.progress = '0';

}

// 此处为了模拟上传进度

uni.showLoading({

title: '上传进度: ' + res.progress + '%'

})

console.log('上传进度' + res.progress);

console.log('已经上传的数据长度' + res.totalBytesSent);

console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);

});

}

}

}

</script>

<style>

.content {

display: flex;

flex-direction: column;

}

</style>

标签:console,log,自定义,res,progress,uni,上传,图片
From: https://www.cnblogs.com/ccVue/p/17490295.html

相关文章

  • Android 12 自定义底部导航栏
    1.修改配置文件 frameworks\base\packages\SystemUI\res\values\config.xml<!--Navbarbuttondefaultordering/layout--><stringname="config_navBarLayout"translatable="false">left[.5W];leftrotate,volume_sub,back,home,r......
  • 自定义异常和统一校验参数
    自定义异常@GetterpublicclassBusinessExceptionextendsRuntimeException{/***http状态码*/privateintcode;privateObjectobject;publicBusinessException(Stringmessage,intcode,Objectobject){super(message);......
  • Hexo + Butterfly 自定义页脚
    原文链接:Hexo+Butterfly自定义页脚推荐阅读基于Hexo从零开始搭建个人博客(一):环境准备基于Hexo从零开始搭建个人博客(二):项目初识基于Hexo从零开始搭建个人博客(三):主题安装基于Hexo从零开始搭建个人博客(四):基础配置基于Hexo从零开始搭建个人博客(五):详细......
  • PHP批量压缩图片,基于TP5,fastadmin
    <?php/***CreatedbyPhpStorm.*User:zhuo<[email protected]>*O(∩_∩)O*Date:2022-7-709:34:38*/namespaceapp\command;usethink\Image;usethink\image\Exception;usethink\console\{Command,Input,Output};//压缩图片classCom......
  • MFC练习2:使用Picture Control控件显示图片
    该方式优点是可以显示JPG等其它格式的图片。一、实验步骤1、使用MFC应用程序向导添加基于对话框的项目;2、在资源视图中拖控件设计UI界面,包含PictureControl和Button共2个控件;3、修改PictureControl控件的Type为Bitmap;4、双击Button按钮编写如下代码voidCpicTestDlg::......
  • backtrader 自定义分析器,解决多股回测难分析困难问题
    backtrader自定义分析器,解决多股回测分析困难问题解决了啥:解决回测后获取关键指标解决多股回测,获取订单分析解决多股回测买卖点可视化标识效果图通过自定义分析器KeyIndicatorAnalyzer,TradeListAnalyzer,获取回测结果数据,通过回测数据可以轻松可视化回测结果。可视化部......
  • 使用Thumbnails进行图片压缩,报“No suitable ImageReader found for source data”异
    先转一次byte数组再处理byte[]bigContent=file.getBytes();Thumbnails.of(newByteArrayInputStream(bigContent)).scale(1f).outputQuality(0.3f).toFile(fileThu);这里fileThu直接使用文件路径比较好......
  • SoapUI 测试上传下载文件
    SoapUI测试上传下载文件 背景使用SoapUI工具测试文件导入导出的接口。 1、文件上传 1)在左侧菜单配置请求URL http://172.31.0.90:38990/file/routerUpload 2)确认请求URL是否正确3)设置介质类型设置为:multipart/form-data4)上传文件(excel类型为例):Attacment......
  • centos添加自定义Systemd服务
    #########################https://zhuanlan.zhihu.com/p/415469149          systemctlenable**nable命令相当于在/etc/systemd/system/目录里添加了一个符号链接,指向/usr/lib/systemd/system/里面的**.service开机时,Systemd会执行/etc/systemd/system......
  • springboot中自定义注解在service方法中,aop失效
    问题描述写了个自定义注解,但是该注解只会出现在serviece层中的方法中。启动发现aop未拦截到问题原因:调用service中的xx()方法时,Spring的动态代理帮我们动态生成了一个代理的对象,暂且叫他$XxxxService。所以调用xx()方法实际上是代理对象$XxxxService调用的。但是在xx()方法内调用同......