前端vue单个文件上传支持图片,压缩包以及文件 , 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13066
前端vue单个文件上传支持图片,压缩包以及文件 , 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13066
效果图如下:
使用方法
<!-- photoList:选择的图片数组 @click:图片选择事件-->
<ccChooseImgsView :photoList="photoList" @click="addPhotoClick"></ccChooseImgsView>
addPhotoClick() {
uni.hideLoading();
let myThis = this;
if (myThis.photoList.length >= 1) {
myThis.photoList = [];
}
uni.chooseImage({
count: 1,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
myThis.photoList = [{'filePath':res.tempFilePaths[0]}];
console.log('选择图片 =' + JSON.stringify(myThis.photoList));
}
});
},
if (this.photoList.length > 0) {
myFilePath = this.photoList[0].filePath;
}
// 服务器地址上传地址 仅为示例,非真实的接口地址
let baseUrl = "http://gzcc.com/cc//appSc/up"
uni.uploadFile({
url: baseUrl, //仅为示例,非真实的接口地址
filePath: myFilePath, //文件路径
name: 'image', //服务端文件接受key
formData: this.myParamData,
success: (uploadFileRes) => {
uni.hideLoading();
let dataDic = JSON.parse(uploadFileRes.data);
console.log('uploadFileRes成功 = ' + JSON.stringify(uploadFileRes));
console.log('datadic成功 = ' + typeof(dataDic));
console.log('code码 = ' + dataDic['code']);
}
});
HTML代码部分
<template>
<view class="content" v-if="seen">
<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">添加房源照片(仅可添加1张)</text>
</view>
<!-- photoList:选择的图片数组 @click:图片选择事件-->
<ccChooseImgsView :photoList="photoList" @click="addPhotoClick"></ccChooseImgsView>
<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';
import ccChooseImgsView from '../../components/ccChooseImgsView.vue';
export default {
components: {
ccChooseImgsView
},
data() {
return {
photoList: [],
seen: true,
myParamData: {},
isClick: false,
};
},
onLoad: function(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;
}
uni.showLoading({
title: '上传中'
})
let myFilePath = '';
if (this.photoList.length > 0) {
myFilePath = this.photoList[0].filePath;
}
// 服务器地址上传地址 仅为示例,非真实的接口地址
let baseUrl = "http://gzcc.com/cc//appSc/up"
uni.uploadFile({
url: baseUrl, //仅为示例,非真实的接口地址
filePath: myFilePath, //文件路径
name: 'image', //服务端文件接受key
formData: this.myParamData,
success: (uploadFileRes) => {
uni.hideLoading();
let dataDic = JSON.parse(uploadFileRes.data);
console.log('uploadFileRes成功 = ' + JSON.stringify(uploadFileRes));
console.log('datadic成功 = ' + typeof(dataDic));
console.log('code码 = ' + dataDic['code']);
}
});
},
addPhotoClick() {
uni.hideLoading();
let myThis = this;
if (myThis.photoList.length >= 1) {
myThis.photoList = [];
}
uni.chooseImage({
count: 1,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
myThis.photoList = [{'filePath':res.tempFilePaths[0]}];
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;
}
.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>
前端vue单个文件上传支持图片,压缩包以及文件 , 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13066的更多相关文章
- thinkphp文件上传以及图片处理
文件上传 上传表单 在ThinkPHP中使用上传功能无需进行特别处理.例如,下面是一个带有附件上传的表单提交: <form action="__URL__/upload" e ...
- vue中el-upload上传多图片且携带参数,批量而不是一张一张的解决方案
现在前端基本不是vue技术栈就是react技术栈. vue技术栈最常用的就是element-ui的ui框架了. 在项目中,我们经常会碰到这种需求:批量上传文件 element-ui 确实也为我们提供了 ...
- MVC&WebForm对照学习:文件上传(以图片为例)
原文 http://www.tuicool.com/articles/myM7fe 主题 HTMLMVC模式Asp.net 博客园::首页:: :: :: ::管理 5 Posts :: 0 ...
- mvc文件上传支持批量上传,拖拽以及预览,文件内容校验等
使用bootstrap-fileinput 使用方式: 1.nuget:Install-Package bootstrap-fileinput 2.语言本地化{下载fileinput_locale_z ...
- .net core版 文件上传/ 支持批量上传,拖拽以及预览,bootstrap fileinput上传文件
asp.net mvc请移步 mvc文件上传支持批量上传,拖拽以及预览,文件内容校验 本篇内容主要解决.net core中文件上传的问题 开发环境:ubuntu+vscode 1.导入所需要的包:n ...
- skymvc文件上传支持多文件上传
skymvc文件上传支持多文件上传 支持单文件.多文件上传 可以设定 文件大小.存储目录.文件类型 //上传的文件目录 $this->upload->uploaddir="att ...
- struts文件上传,获取文件名和文件类型
struts文件上传,获取文件名和文件类型 Action中还有两个属 性:uploadFileName和uploadContentType,这两个属性分别用于封装上传文件的文件名.文件类型.这是S ...
- 【FTP】java FTPClient 文件上传内容为空,文件大小为0
问题:如题所述,使用FTPClient上传至FTP服务器, 表现如下:①文件大小为0 ②上传很小的文件,但是要花费很长的时间,20K要花费2分钟甚至更久 ③没有任何的报错,没有任何的乱码 解决方法: ...
- Spring4 MVC 多文件上传(图片并展示)
开始需要在pom.xml加入几个jar,分别是 <dependency> <groupId>commons-fileupload</groupId> <art ...
- spring实现文件上传(图片解析)
合抱之木,生于毫末,千里之行,始于足下,要想了解spring的文件上传功能,首先要知道spring是通过流的方式将文件进行解析,然后上传.那么是不是所有需要用的文件上传的地方都要写一遍文件解析器呢? ...
随机推荐
- golang pprof 监控系列(3) —— memory,block,mutex 统计原理
golang pprof 监控系列(3) -- memory,block,mutex 统计原理 大家好,我是蓝胖子. 在上一篇文章 golang pprof监控系列(2) -- memory,bloc ...
- 二进制安装Kubernetes(k8s) v1.24.2 IPv4/IPv6双栈
二进制安装Kubernetes(k8s) v1.24.2 IPv4/IPv6双栈 Kubernetes 开源不易,帮忙点个star,谢谢了 介绍 kubernetes二进制安装 强烈建议在Github ...
- python之re详解
import re# .匹配任何一个字符,除了换行#[]匹配里面任意一个字符# \d匹配一个数字0-9# \D匹配不是一个数字# \s 匹配一个空格和tab# \S 匹配非空格和tab一个字符# \w ...
- pandas之excel操作
Excel 是由微软公司开发的办公软件之一,它在日常工作中得到了广泛的应用.在数据量较少的情况下,Excel 对于数据的处理.分析.可视化有其独特的优势,因此可以显著提升您的工作效率.但是,当数据量非 ...
- 5.mapper出错原因
1.总结:前个星期mapper出错,很大原因是自己的项目结构创建有问题,大项目下应该是spring init那种项目结构形式,但是在创建多模块的时候应该是使用moudle形式的项目结构: 所以自己在运 ...
- python过滤列表元素
li = [1, 2, 3, 4, 5, 6] def fun(item, num): if item == num: return 1 else: return 0 def fun1(item, n ...
- ES6教程笔记
ES介绍 什么是ES ES全称 EcmaScript 是一种脚本语言的规范 Javascript为ES的实现 Ecma 是一个组织 Ecma组织 为什么要学习ES6? ES6的版本变动内容最多,具有里 ...
- springboot-poi ---封装注解式导入导出
此demo 是基于poi封装对象式注解导入导出,项目框架为springboot项目! 简单的说明一下此demo涉及到的知识点,希望能给初学者带来方便! poi-excel 基本操作(工具) 自定义注解 ...
- WPF 屏幕点击的设备类型
1.鼠标 可以通过Mouse相关的事件参数MouseButtonEventArgs中的数据,e.StylusDecice==null表示没有触摸设备,所以设备为鼠标 2.触笔 or 触摸 根据Styl ...
- 民谣女神唱流行,基于AI人工智能so-vits库训练自己的音色模型(叶蓓/Python3.10)
流行天后孙燕姿的音色固然是极好的,但是目前全网都是她的声音复刻,听多了难免会有些审美疲劳,在网络上检索了一圈,还没有发现民谣歌手的音色模型,人就是这样,得不到的永远在骚动,本次我们自己构建训练集,来打 ...