广告
返回顶部
首页 > 资讯 > 精选 >vue+element upload上传带参数的方法
  • 334
分享到

vue+element upload上传带参数的方法

2023-06-30 09:06:26 334人浏览 八月长安
摘要

今天小编给大家分享一下Vue+element upload上传带参数的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一

今天小编给大家分享一下Vue+element upload上传带参数的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

element upload上传带参数

<el-button  size="small" type="success" @click="submitUpload">保存</el-button>
   <el-upload    class="upload-demo"    ref="upload"    :action="action()"    :on-preview="handlePreview"    :before-upload="beforeUpload"      :data="uploadData"        :on-error = "error"    :on-success="successResave"    :on-remove="handleRemove"    :file-list="fileList"    :auto-upload="false">    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>    <!-- <el-button  size="small" type="success" @click="submitUpload">上传到服务器</el-button> -->    <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->    </el-upload>

data里面参数

uploadData:null,

methods里面

action(){       return this.portC+"uplodResultsScore"     },     //上传     submitUpload() {         this.$refs.upload.submit();      },      handleRemove(file, fileList) {        console.log(file, fileList);      },      handlePreview(file) {         console.log(file);      },      beforeUpload (file) {                        this.uploadData = {dstype:this.proType,name:this.mobanname,dsmark:this.value5,};             console.log(this.uploadData)            let promise = new Promise((resolve) => {                this.$nextTick(function () {                    resolve(true);                });            });            return promise; //通过返回一个promis对象解决     },     //上传成功钩子     successResave(response, file, fileList){           console.log(response)           if(response.code==10001){              alert("保存成功")                 this.proType="";               this.mobanname="";               this.value5="";               this.$router.push("/moban")           }     },    //失败钩子     error(response, file, fileList){           console.log(response)     },     //选择家化实效      selectType(val){         console.log(val)         if(val==1){             this.$router.push("/new")         }else{             this.$router.push("/new1")         }      },

效果图

vue+element upload上传带参数的方法

element上传函数带参数,自定义传参

下面这是标签

可以看出来 :

Http-request="(params) =>beforeMasterPictureUpload(params,‘ruleFORM',fileList0)"

http-request 传递参数的方法 是可以这样写的,其他方法一样,但是如果写错少些可能会导致覆盖原来的方法。

<el-upload :class="{hidesse:hideUpload0,'avatar-uploader':true}"                         multiple action="这里不需要填或者随便写"                        list-type="picture-card" :before-upload="beforeAvatarUpload"                        :on-preview="(params) =>handlePictureCardPreview(params,'ruleForm',fileList0)"                        :http-request="(params) =>beforeMasterPictureUpload(params,'ruleForm',fileList0)"                        :on-change="(params,fileList) =>onChangeMaster(params,fileList,'ruleForm','fileList0')"                        :on-exceed="OnExceed"                        :on-remove="(params) =>handleRemove(params,'ruleForm',fileList0,'fileList0')" :limit="5"                        :file-list="fileList0" @click="titext">                        <i class="el-icon-plus"></i>                    </el-upload>

下面是js 接受方法 同样 我们拿 http-request 这个方法做例子

beforeMasterPictureUpload(params, fromData, prop) {    console.log('----aaaa', this.fileList);    console.log('file', params, fromData, prop);}

大家可以输出看看结果 是否有拿到你上面传递过来的字符串或者是值

我将源码放上

html标签

<el-upload :class="{hidesse:hideUpload0,'avatar-uploader':true}"                         multiple action="这里不需要填或者随便写"                        list-type="picture-card" :before-upload="beforeAvatarUpload"                        :on-preview="(params) =>handlePictureCardPreview(params,'ruleForm',fileList0)"                        :http-request="(params) =>beforeMasterPictureUpload(params,'ruleForm',fileList0)"                        :on-change="(params,fileList) =>onChangeMaster(params,fileList,'ruleForm','fileList0')"                        :on-exceed="OnExceed"                        :on-remove="(params) =>handleRemove(params,'ruleForm',fileList0,'fileList0')" :limit="5"                        :file-list="fileList0" @click="titext">                        <i class="el-icon-plus"></i>                    </el-upload>

JS语句

// 主图上传之前                beforeAvatarUpload(file) {                    console.log('主图上传之前:', file)                    const idJPG =                        file.type === "image/jpeg" || "image/gif" || "image/png" || "image/bmp";                    if (!idJPG) {                        this.$message.error(                            '123123'                        );                    }                    return idJPG;                },                // 图片触发                onChangeMaster(file, fileList, fromData, prop) {                    // fileList 当前上传框的数据                     switch (prop) {                        case 'fileList0':                            { this.hideUpload0 = fileList.length >= this.limitCount; }                            break;                        case 'fileList1':                            { this.hideUpload1 = fileList.length >= this.limitCount; }                            break;                        case 'fileList2':                            { this.hideUpload2 = fileList.length >= this.limitCount; }                            break;                        case 'fileList3':                            { this.hideUpload3 = fileList.length >= this.limitCount; }                            break;                        case 'fileList4':                            { this.hideUpload4 = fileList.length >= this.limitCount; }                            break;                        case 'fileList5':                            { this.hideUpload6 = fileList.length >= this.limitCount; }                            break;                        default:                            break;                    }                    console.log('判断一次', file, fileList, this.fileList0)                    if (this.inde > 0) {                        return                    } else {                        //let existFile = fileList.slice(0, fileList.length - 1).find(f => f.name === file.name)                        //if (existFile) {                           // this.inde++                          //  console.log(existFile)                          //  this.$message.error(                          //      '图片重复' + existFile.name                        //    );                        //    // fileList.pop()                     //   }                        this[prop] = fileList                    }                },                // 图片个数超出限制                OnExceed(file, fileList) {                    this.$message.error(                        '每个选项最多上传5张', "error"                    );                },                handleRemove(params, fileList, prop, item) {                    prop.forEach((obj, index) => {                        console.log(index, obj)                        if (params.uid == obj.uid) {                            prop.splice(index, 1)                        }                    })                    console.log('删除后的数组', prop);                    setTimeout(() => {                        switch (item) {                            case 'fileList0':                                { this.hideUpload0 = prop.length >= this.limitCount; }                                break;                            case 'fileList1':                                { this.hideUpload1 = prop.length >= this.limitCount; }                                break;                            case 'fileList2':                                { this.hideUpload2 = prop.length >= this.limitCount; }                                break;                            case 'fileList3':                                { this.hideUpload3 = prop.length >= this.limitCount; }                                break;                            case 'fileList4':                                { this.hideUpload4 = prop.length >= this.limitCount; }                                break;                            case 'fileList5':                                { this.hideUpload6 = prop.length >= this.limitCount; }                                break;                            default:                                break;                        }                        console.log(prop.length >= this.limitCount)                    }, 1000)                    // this.fileList = [];                    this.dialogImageUrl = '';                },                handlePictureCardPreview(file, fromData, prop) {                    console.log(file, fromData, prop)                    this.dialogImageUrl = file.url;                    this.dialogVisible = true;                },                beforeMasterPictureUpload(params, fromData, prop) {                    console.log('----aaaa', this.fileList);                    console.log('file', params, fromData, prop);                                    },

这是需求案列

vue+element upload上传带参数的方法

以上就是“vue+element upload上传带参数的方法”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注编程网精选频道。

--结束END--

本文标题: vue+element upload上传带参数的方法

本文链接: https://www.lsjlt.com/news/328028.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • vue+element upload上传带参数的方法
    今天小编给大家分享一下vue+element upload上传带参数的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一...
    99+
    2023-06-30
  • vue+element upload上传带参数的实例
    目录element upload上传带参数element上传函数带参数,自定义传参下面这是标签我将源码放上这是需求案列element upload上传带参数 <el-butto...
    99+
    2022-11-13
  • 解析element-ui中upload组件传递文件及其他参数的问题
    最近项目用到了vuethink,里面集成了element-ui,之前一直用的是bootstrap框架,对js也是一知半解,然后也用过vue.js,但也是学的不通透的,然后就各种入坑。...
    99+
    2022-11-12
  • 如何解析element-ui中upload组件传递文件及其他参数的问题
    如何解析element-ui中upload组件传递文件及其他参数的问题,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。最近项目用到了vuethink,里面集成了e...
    99+
    2023-06-25
  • Flask带参URL传值的实现方法
    目录Flask带参URL传值的方法定义一个包含动态路由的Flask处理类页面我们看控制台还有一种URL传值的格式接收参数的代码Flask传参定义id 及通过传参定义属性名称Flask...
    99+
    2022-11-11
  • Vue实现带参跳转的方法
    这篇文章主要介绍了Vue实现带参跳转的方法,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。主页面:name —> shishengzuotanhuichaxun此页面表格...
    99+
    2023-06-14
  • vue 中 get / delete 传递数组参数方法
    在前后端交互的时候,有时候需要通过 get 或者 delete 传递一个数组给后台,但是这样直接传递后台无法接收数据,因为在传递的过程中数组参数会被转译,结果如下: 参数...
    99+
    2022-11-11
  • vue中get方法和post方法怎么传递数组参数
    这篇文章主要介绍了vue中get方法和post方法怎么传递数组参数的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中get方法和post方法怎么传递数组参数文章都会有所收获,下面我们一起来看看吧。1、vue...
    99+
    2023-07-05
  • vue中的get方法\post方法如何实现传递数组参数
    目录get方法\post方法如何传递数组参数第一部分:vue中get方法如何传递数组参数 下面列出我的接口格式及解决方法的源码vue get与post传参方式1.post:...
    99+
    2022-11-13
  • vue跳转页签传参并查询参数的方法是什么
    本篇内容主要讲解“vue跳转页签传参并查询参数的方法是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“vue跳转页签传参并查询参数的方法是什么”吧!场景需求是要求通过点击用户ID或者昵称 跳转...
    99+
    2023-07-06
  • vue中get方法\post方法如何传递数组参数详解
    目录1、vue中get方法如何传递数组参数2、vue get与post传参方式2.1post:用data传递参数2.2get:用params传递参数附:uniapp使用uview报错...
    99+
    2023-03-23
    vue参数传递 vue的get请求传入数组参数 vue get请求传递参数
  • php函数参数的传递方法
    这篇文章给大家分享的是有关php函数参数的传递方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。在调用函数时,需要向函数传递参数,被传入函数的参数称为实参,而函数定义的参数称为形参。而向函数传递参数的方式有四种,...
    99+
    2023-06-14
  • Vue的URL转跳与参数传递方法是什么
    这篇“Vue的URL转跳与参数传递方法是什么”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Vue的URL转跳与参数传递方法是...
    99+
    2023-07-05
  • dedecms 5.7 文章不能上传图片的解决方法(Upload filetype not allow)
    如果你后台设置可以上传图片,而上传图片出现 Upload filetype not allow ! 仅需要修改一个字母,即可解决问题! [upload=1] 请修改 /include/uploadsafe.inc.php...
    99+
    2022-06-12
    文章 上传图片
  • el-uploadhttp-request使用多个文件上传携带其他参数方式
    目录el-upload http-request使用el-upload自定义http-request上传踩坑el-upload http-request使用 1、http-reque...
    99+
    2022-11-13
  • shell传参并将参数传递给sql文件的方法
    如下所示: 调用代码:   sh /tmp/t.sh 20160808  echo $1 cat /tmp/t.sql | sedyLEEDe '$s/ssssss/'$1'/g' ...
    99+
    2022-06-04
    shell 传参 sql
  • Vue中$router.push()路由切换、传参和获取参数的方法是什么
    这篇文章主要介绍“Vue中$router.push()路由切换、传参和获取参数的方法是什么”,在日常操作中,相信很多人在Vue中$router.push()路由切换、传参和获取参数的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好...
    99+
    2023-07-05
  • Python传入参数的几种方法
    Python传入参数的方法有:位置参数、默认参数、可变参数、关键字参数、和命名关键字参数、以及各种参数调用的组合 Python唯一支持的参数传递方式是『共享传参』(call by sharing) 多数面向对象语言都采用这...
    99+
    2023-01-31
    几种方法 参数 Python
  • Shell参数传递的使用方法
    我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为: $n。n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…...
    99+
    2023-05-19
    Shell 参数传递 Shell 传递参数
  • Shell 参数传递的使用方法
    我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为: $n。n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推……具体实例:以下实例我们向脚本传递三个参数,并分别输出...
    99+
    2023-05-12
    Shell 参数传递 Shell 传递参数
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作