直接看代碼:前端實現(xiàn)
<div class="upload">
<el-upload
class="upload-demo"
name="upload_name"
:data="{'user_name':user_name}"
action="http://localhost:8000/api/deal_pest_Image"
:show-file-list="false"
:on-success="handleSucess"
>
<el-button size="small" type="primary">點擊上傳</el-button>
</el-upload>
</div>
注意data必須是object類型即鍵值對類型
處理成功的回調(diào)
handleSucess(response, file, fileList){
console.log('response', response)
if(response.code === 200){
this.$message({
message: '上傳并處理成功',
type: 'success'
});
this.init()
}else {
this.$message.error('出錯了,請稍后重試');
}
},
按下點擊上傳按鈕,選擇圖片后即可向action=http://localhost:8000/api/deal_pest_Image這個地址上傳如下圖:
可以看出瀏覽器發(fā)送的是post請求,請求參數(shù)如下:
文章來源:http://www.zghlxwxcb.cn/news/detail-651257.html
所以后端用post方式接收即可,Python的案例:
文章來源地址http://www.zghlxwxcb.cn/news/detail-651257.html
到了這里,關(guān)于使用element UI 的el-upload上傳圖片并攜帶參數(shù)的用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!