elementui php上传图片,element-ui upload组件多文件上传的示例代码

之前有一篇写的如何同时传递form表单及upload组件文件,如果有多个upload文件该如何传递呢

上代码

html

v-for="item in groupOptions"

:key="item.groupId"

:label="item.groupName"

:value="item.groupId">

v-for="item in subGroupOptions"

:key="item.subGroupId"

:label="item.subGroupName"

:value="item.subGroupId">

class="upload-demo"

drag

ref="uploadhtml"

:action="upload_url"

:auto-upload="false"

:before-upload="newHtml"

accept=".html, .htm">

将文件拖到此处,或 点击上传
实验信息上传,只能传(.html/.htm)文件

class="upload-demo"

drag

ref="uploadfile"

:action="upload_url"

:auto-upload="false"

:before-upload="newFiles"

multiple>

将文件拖到此处,或 点击上传
实验信息附件上传,只能传(.file)文件

class="upload-demo"

drag

ref="uploadvideo"

:action="upload_url"

:auto-upload="false"

:before-upload="newVideo"

accept=".mp4">

将文件拖到此处,或 点击上传
实验视频上传,只能传(.mp4)文件

确 定

重 置

js

data () {

return {

upload_url: 'aaa', // 随便填一个,但一定要有

uploadForm: new FormData(), // 一个formdata

rules: {}, // 用到的规则

newform: {

expName: '',

groupName: '',

expSn: '',

subGroupName: '',

expvmDifficulty: 1

}

}

}

methods

newSubmitForm () {

this.$refs['newform'].validate((valid) => {

if (valid) {

this.uploadForm.append('expName', this.newform.expName)

this.uploadForm.append('expSn', this.newform.expSn)

this.uploadForm.append('groupId', this.newgroupId)

this.uploadForm.append('subGroupId', this.newsubgroupId)

this.uploadForm.append('expvmDifficulty', this.newform.expvmDifficulty)

newExp(this.uploadForm).then(res => {

if (res.code === 400) {

this.$message.error(res.error)

} else if (res.code === 200) {

this.$message.success('上传成功!')

}

})

this.$refs.uploadhtml.submit() // 提交时触发了before-upload函数

this.$refs.uploadfile.submit()

this.$refs.uploadvideo.submit()

} else {

console.log('error submit!!')

return false

}

})

},

newHtml (file) { // before-upload

this.uploadForm.append('html', file)

return false

},

newFiles (file) {

this.uploadForm.append('file[]', file)

return false

},

newVideo (file) {

this.uploadForm.append('video', file)

return false

}

newExp函数是作为一个前后端交互的函数

export function newExp (data) {

return axios({

method: 'post', // 方式一定是post

url: '你的后台接收函数路径',

timeout: 20000,

data: data // 参数需要是单一的formData形式

})

}

PHP代码,后台接收

public function newExp() {

$param = $this->request->post(); // 获取页面表单传值

$files = $this->request->file(); // 接收到的文件

}

注意

this.uploadForm.append('file[]', file)

这里是接收多文件一定要是数组形式的file[]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
element-ui的v-for循环el-upload上传文件的代码示例可以参考以下内容: 引用中的代码展示了一个使用v-for循环的表单元素,其中包含了一个el-upload组件用于上传文件。每次循环都会生成一个包含el-upload的div元素,可以根据需要进行多次循环。在el-upload中,可以设置上传文件的相关属性,如action、accept等。同时还可以设置el-image组件用于显示已上传的图片。这个例子可以作为参考来实现element-ui v-for循环el-upload上传文件的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [element-ui v-for循环el-upload上传图片](https://blog.csdn.net/qq_21275565/article/details/121257628)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [element-ui el-upload实现上传文件以及简单的上传文件格式验证](https://blog.csdn.net/w1060436872/article/details/126544548)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [vue-cli3.0+element-ui上传组件el-upload的使用](https://download.csdn.net/download/weixin_38617335/12949215)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值