u-upload组件多图片上传提交表单

上传的组件:<u-upload @on-list-change="onListChange" :fileList="fileList" @delete="deletePic" name="files" :auto-upload="true"
                multiple :header="getAuthorizationHeader()" :action="dynamicAction" @on-success="onSuccess" max-count="9">
            </u-upload>

注:这里的dynamicAction是上传地址,getAuthorizationHeader是请求头,onSuccess上传成功函数,原先的@after那个已经弃用了,最大限制max-count="9",这里最多可以设置为99张图片,:auto-upload="true"自动上传方法,onListChange当内部文件列表被加入文件、移除文件,或手动调用clear方法时触发。

表单按钮:<button class="sub-suggestion" @click="subOpinion">提交</button>

export default {
        data() {
            return {
                selectCategory: 0,
                describe: '',
                fileList: [],
                imageList:[],
                photoNum:'',
                dynamicAction: config.baseUrl + 'File/LeaveRecordFile',
                appenDix: '',
                baseUrl: config.baseUrl
            }
        },
        methods: {
            handleSelectCategory(category) {
                if (this.selectCategory === category) {
                    this.selectCategory = 0; // 取消选中
                } else {
                    this.selectCategory = category; // 更新选中的分类
                }
                console.log(this.selectCategory);
            },
            getAuthorizationHeader() {
                const token = uni.getStorageSync('token');
                return {
                    Authorization: `Bearer ${token}`,
                };
            },
            onListChange(lists,name) {
                this.photoNum = lists.length
            },
            onSuccess(data, index, lists, name) {
                let url = data.data.url
                this.imageList.push(url)
                this.appenDix =JSON.stringify(this.imageList)
            },
            subOpinion() {
                const submissionData = {
                    suggestedContent: this.describe,
                    category: this.selectCategory,
                    annex: this.appenDix
                }
                apiAddOpinion(submissionData).then(res => {
                    console.log(res.message)
                    if (res.code === 0) {
                        uni.redirectTo({
                            url: '/pages/other/opinion/opinion'
                        })
                    }
                })
            }

最后就大功告成啦!当然上传地址根据自己的来。

  • 17
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
控件UpdloadFile文件上传eg: string newfilename = file_uploadid.FileName; string size = file_uploadid.PostedFile.ContentLength.ToString(); string type = file_uploadid.PostedFile.ContentType; string type2 = newfilename.Substring(newfilename.LastIndexOf(".") + 1); string path = ""; try { if (file_uploadid.PostedFile != null && file_uploadid.PostedFile.FileName != "") { string hzm = System.IO.Path.GetExtension(file_uploadid.PostedFile.FileName);//后缀名 如 .doc string[] a = { ".txt", ".jpg", ".jpeg", ".gif", ".png", ".docx", ".doc", ".xlsx", ".xls", ".rar", ".zip", ".pdf" };//设定好了的格式 if (!a.Contains(hzm)) { Response.Write("文件格式不正确"); } else { int defaulsize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["filesize"]);//取得设置的默认文件的大小 int filesize = (file_uploadid.PostedFile.ContentLength) / 1024; //取得上传的文件的大小,单位为bytes if (filesize < defaulsize) { #region 对文件进行操作 newfilename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + hzm;//文件的新名字 如20120711105734222.doc path = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile//");//文件保存的路径 if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } #endregion } else { //超过了文件的大小 Response.Write("上传的文件超过了3000M,请重新选择 "); } } } } catch (Exception) { Response.Write("文件格式不正确"); } #endregion if (newfilename != "") { file_uploadid.SaveAs(path + newfilename); //保存文件 }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值