前端vue uni-app多图片上传组件,支持单个文件,多个文件上传 步骤条step使用
快速实现多图片上传组件,支持单个文件,多个文件上传 步骤条step使用; 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12747
效果图如下:
使用方法
// 添加多张图片(少于6张)
addPhotoClick() {
uni.hideLoading();
let myThis = this;
if (myThis.photoList.length >= 6) {
myThis.photoList = [];
}
uni.chooseImage({
count: 6,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
for (let j = 0; j < res.tempFilePaths.length; j++) {
// name:服务端文件接受key filePath: 需与服务端文件接收字段保持一致
let tmpdict = {
'name': 'image',
'filePath': res.tempFilePaths[j]
};
myThis.photoList.push(tmpdict);
}
console.log('选择图片 =' + JSON.stringify(myThis.photoList));
}
});
}
// 服务器地址上传地址 仅为示例,非真实的接口地址
let baseUrl = "http://gzcc.com/cc//appSc/up"
console.log('图片资源 = ' + JSON.stringify(this.photoList))
console.log('请求参数 = ' + JSON.stringify(this.myParamData));
uni.uploadFile({
url: baseUrl, //仅为示例,非真实的接口地址
files: this.photoList,
formData: this.myParamData,
success: (uploadFileRes) => {
uni.hideLoading();
console.log('上传成功 = ' + uploadFileRes.data);
}
});
HTML代码部分
<template>
<view class="content" v-if="seen">
<uni-steps style="margin-top: 16px; margin-bottom: 16px;"
:options="[{title: '基本信息'}, {title: '房源信息'}, {title: '补充信息'}, {title: '提交成功'}]" :active="2"
active-color='#007AFF'></uni-steps>
<view class="lineView"></view>
<form @submit="formSubmit" @reset="formReset">
<view class="inputView">
<text class="leftTitle">交通指引</text>
</view>
<textarea class="rightTextarea" name="direct" placeholder=" 请输入交通指引" />
<view class="inputView">
<text class="leftTitle">房屋介绍</text>
</view>
<textarea class="rightTextarea" name="village" placeholder=" 请输入房屋介绍" />
<view class="inputView">
<text class="leftTitle">添加房源照片(最多可添加6张)</text>
</view>
<view class="tagView">
<!-- 自定义了一个data-id的属性,可以通过js获取到它的值! hover-class 指定按下去的样式类-->
<image class="addPhotoV" mode="aspectFill" v-for="(item, index) in photoList" :key="index"
:src="item.filePath">
</image>
<image class="addPhotoV" mode="center" @click="addPhotoClick" src="../../static/repair_camera.png">
</image>
</view>
<view class="uni-btn-v">
<button class="botBtn" type="primary" form-type="submit">提交</button>
<view class="tipText"> 注意事项: 请确保您填写的房屋信息真实无误 </view>
</view>
</form>
</view>
</template>
JS代码 (引入组件 填充数据)
<script>
import Vue from 'vue';
export default {
data() {
return {
photoList: [],
seen: true,
myParamData: {},
isClick: false,
};
},
onLoad: function(e) {
if (typeof(e.myParamData) === 'string') {
this.myParamData = JSON.parse(e.myParamData);
console.log('页面3 数据 = ' + JSON.stringify(e));
}
},
methods: {
formSubmit: function(e) {
console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value));
if (this.isClick) {
let that = this;
setTimeout(function() {
that.isClick = false;
}, 600)
return;
}
this.isClick = true;
var formdata = e.detail.value;
this.myParamData = Object.assign(this.myParamData, formdata);
console.log('页面3 myParamData=' + JSON.stringify(this.myParamData));
if (formdata['direct'].length < 2) {
uni.showModal({
content: '请输入交通指引',
showCancel: false
});
return;
}
if (formdata['village'].length < 2) {
uni.showModal({
content: '请输入所在小区介绍',
showCancel: false
});
return;
}
if (this.photoList.length < 1) {
uni.showModal({
content: '请添加房源照片',
showCancel: false
});
return;
}
if (this.photoList.length > 6) {
uni.showModal({
content: '最多只能选择提交6张图片',
showCancel: false
});
return;
}
uni.showLoading({
title: '上传中'
})
// 服务器地址上传地址 仅为示例,非真实的接口地址
let baseUrl = "http://gzcc.com/cc//appSc/up"
console.log('图片资源 = ' + JSON.stringify(this.photoList))
console.log('请求参数 = ' + JSON.stringify(this.myParamData));
uni.uploadFile({
url: baseUrl, //仅为示例,非真实的接口地址
files: this.photoList,
formData: this.myParamData,
success: (uploadFileRes) => {
uni.hideLoading();
console.log('上传成功 = ' + uploadFileRes.data);
}
});
},
// 添加多张图片(少于6张)
addPhotoClick() {
uni.hideLoading();
let myThis = this;
if (myThis.photoList.length >= 6) {
myThis.photoList = [];
}
uni.chooseImage({
count: 6,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
for (let j = 0; j < res.tempFilePaths.length; j++) {
// name:服务端文件接受key filePath: 需与服务端文件接收字段保持一致
let tmpdict = {
'name': 'image',
'filePath': res.tempFilePaths[j]
};
myThis.photoList.push(tmpdict);
}
console.log('选择图片 =' + JSON.stringify(myThis.photoList));
}
});
}
}
};
</script>
CSS
<style>
.uni-form-item .title {
padding: 20rpx 0;
}
.content {
display: flex;
flex-direction: column;
width: 100%;
height: auto;
}
.inputView {
flex-direction: row;
display: flex;
height: 40px;
align-items: center;
width: 100%;
}
.line {
width: 90%;
height: 2rpx;
margin-left: -2rpx;
background-color: #f8f8f8;
margin-left: 5%;
}
.leftTitle {
margin-left: 40rpx;
width: 284px;
height: 32px;
line-height: 32px;
font-size: 28rpx;
color: #333333;
}
.rightTextarea {
margin-left: 5%;
width: 90%;
height: 106px;
line-height: 40rpx;
border-radius: 12rpx;
border: solid 1px #F5F5F5;
font-size: 15px;
}
.addPhotoV {
margin-top: 7px;
margin-bottom: 7px;
width: calc((100vw - 70px)/3);
height: calc((100vw - 70px)/3.16);
margin-left: 17.5px;
border-radius: 12rpx;
border: solid 1px rgba(58.04%, 76.08%, 88.24%, 0.6);
}
.uni-btn-v {
width: 100%;
height: auto;
}
.botBtn {
width: 90%;
margin-top: 36px;
height: 48px;
}
.tipText {
width: 100%;
margin-left: 0px;
text-align: center;
color: #666666;
margin-top: 36px;
margin-bottom: 36px;
font-size: 28rpx;
}
</style>
.uni-form-item .title { }
.content { display: flex; flex-direction: column; width: 100%; height: auto }
.inputView { flex-direction: row; display: flex; height: 40px; align-items: center; width: 100% }
.line { width: 90%; background-color: rgba(248, 248, 248, 1); margin-left: 5% }
.leftTitle { width: 284px; height: 32px; line-height: 32px; color: rgba(51, 51, 51, 1) }
.rightTextarea { margin-left: 5%; width: 90%; height: 106px; border: 1px solid rgba(245, 245, 245, 1); font-size: 15px }
.addPhotoV { margin-top: 7px; margin-bottom: 7px; width: calc((100vw - 70px) / 3); height: calc((100vw - 70px) / 3.16); margin-left: 17.5px }
.uni-btn-v { width: 100%; height: auto }
.botBtn { width: 90%; margin-top: 36px; height: 48px }
.tipText { width: 100%; margin-left: 0; text-align: center; color: rgba(102, 102, 102, 1); margin-top: 36px; margin-bottom: 36px }
前端vue uni-app多图片上传组件,支持单个文件,多个文件上传 步骤条step使用的更多相关文章
- 分享一个react 图片上传组件 支持OSS 七牛云
react-uplod-img 是一个基于 React antd组件的图片上传组件 支持oss qiniu等服务端自定义获取签名,批量上传, 预览, 删除, 排序等功能 需要 react 版本大于 v ...
- js_ajax模拟form表单提交_多文件上传_支持单个删除
需求场景: 用一个input type="file"按钮上传多张图片,可多次上传,可单独删除,最后使用ajax模拟form表单提交功能提交到指定方法中: 问题:由于只有一个file ...
- Jquery的一键上传组件OCUpload及POI解析Excel文件
第一步:将js文件引入页面 <script type="text/javascript" src="${pageContext.request.contextPat ...
- SpringBoot 整合文件上传 elment Ui 上传组件
SpringBoot 整合文件上传 elment Ui 上传组件 本文章记录 自己学习使用 侵权必删! 前端代码 博主最近在学 elment Ui 所以 前端使用 elmentUi 的 upload ...
- ASP.NET Core WEB API 使用element-ui文件上传组件el-upload执行手动文件文件,并在文件上传后清空文件
前言: 从开始学习Vue到使用element-ui-admin已经有将近快两年的时间了,在之前的开发中使用element-ui上传组件el-upload都是直接使用文件选取后立即选择上传,今天刚好做了 ...
- 基于SqlSugar的开发框架循序渐进介绍(13)-- 基于ElementPlus的上传组件进行封装,便于项目使用
在我们实际项目开发过程中,往往需要根据实际情况,对组件进行封装,以更简便的在界面代码中使用,在实际的前端应用中,适当的组件封装,可以减少很多重复的界面代码,并且能够非常简便的使用,本篇随笔介绍基于El ...
- 使用swfupload上传超过30M文件,使用FLASH上传组件
原文:使用swfupload上传超过30M文件,使用FLASH上传组件 前一段时间会员的上传组件改用FLASH的swfupload来上传,既能很友好的显示上传进度,又能完全满足大文件的上传. 后来服务 ...
- 【Vue】计算属性 监听属性 组件通信 动态组件 插槽 vue-cli脚手架
目录 昨日回顾 1 计算属性 插值语法+函数 使用计算属性 计算属性重写过滤案例 2 监听属性 3 组件介绍和定义 组件之间数据隔离 4 组件通信 父子通信之父传子 父子通信之子传父 ref属性 扩展 ...
- Vue.js基础语法(二)组件
vue学习的一系列,全部来自于表哥---表严肃,是我遇到过的讲课最通透,英文发音最好听的老师,想一起听课就去这里吧 https://biaoyansu.com/i/hzhj1206 把一段经常要用的东 ...
- Vue.js 学习笔记 第7章 组件详解
本篇目录: 7.1 组件与复用 7.2 使用props传递数据 7.3 组件通讯 7.4 使用slot分发内容 7.5 组件高级用法 7.6 其他 7.7 实战:两个常用组件的开发 组件(Compon ...
随机推荐
- Unity3D中的Attribute详解(六)
本文将重点对Unity剩下常用的Attribute进行讲解,其他不常用的Attribute各位可以自行去官方文档查阅. 首先是UnityEngine命名空间下的. ColorUsage,这个主要作用于 ...
- yaml-cpp YAML格式处理库的介绍和使用(面向业务编程-文件格式处理)
yaml-cpp YAML格式处理库的介绍和使用(面向业务编程-文件格式处理) YAML格式介绍 YAML的格式介绍,有关ini.json和xml或许很多人已经很了解了,但是关于YAML,还有许多人不 ...
- IDEA中隐藏问文件或者文件夹
点击+,输入要隐藏的文件名,支持*通配符 回车确认
- FTP FileZilla 425 Can't open data connection for transfer of "/" 错误: 读取目录列表失败
如图所示: 在谷歌百度搜了很多资料都没有解决,主动被动模式端口入站规则什么能设置的都设置了结果还是不行,尝试换了一个软件用了FTP Rush就直接可以连上了. 具体原因有空再查找吧,目前问题算是解决了 ...
- 什么是BFC,BFC的作用,以及怎么触发BFC
什么是BFC: 块级格式化上下文 BFC的作用: BFC其实就是规定了网页布局的规范 1.BFC就是页面上的一个独立容器,容器里面的元素不会影响到外面的元素 解释:BFC的基本改变,最 ...
- Python 使用QQ 邮箱进行发送邮件及经验总结
今天我带大家实现下简单的发邮件功能.我们要使用到email和smtplib库,这两个库时python自带的,直接import 引用就好了,实现环境python3.6. 对QQ邮箱进行开启SMTP服务 ...
- 洛谷:P5716日份天数
题目描述 输入年份和月份,输出这一年的这一月有多少天.需要考虑闰年. 输入格式 输入两个正整数,分别表示年份 \(y\) 和月数 \(m\),以空格隔开. 输出格式 输出一行一个正整数,表示这个月有多 ...
- Email发送邮件使用ical4j将时间同步日历中
1.Maven依赖 <!--邮件--> <dependency> <groupId>org.springframework.boot</groupId> ...
- C# 获取所有桌面窗口信息
窗口标题.窗口类名.是否可见.是否最小化.窗口位置和大小.窗口所在进程信息 1 private static WindowInfo GetWindowDetail(IntPtr hWnd) 2 { 3 ...
- Win Airtest + 夜神模拟器 实现APP自动化
前言: Airtest 是一个跨平台的UI自动化测试框架,适用于游戏和App.目前支持Windows.Android平台和 iOS 平台. 一.下载Airtest 下载地址:https://airte ...