vue+elementui的table行內實現el-upload文件上傳
直接上代碼
<el-table :data="tableData">
<el-table-column prop="file_name" lable="文件名稱">
<template scope="scope">
<el-input v-model="scope.row.file_name" placeholder="請輸入文件名稱"></el-input>
</template>
</el-table-column>
<el-table-column>
<template scope="scope">
<el-upload ref="upload" :data="uploadData" :show-file-list="false" action="uploadUrl" :on-success="handleSucess" :on-error="handleError" :auto-upload="true">
<el-button size="small" type="primary" @click="curRowIndex=scope.$index">點擊上傳</el-button>
/*主要特別注意這裏新增的@click方法將當前的index值賦值一個變量,不然沒法獲取到對應的行信息*/
</el-upload>
</template>
</el-table-column>
</el-table>
<script>
export default{
data() {
return {
tableData: [],
uploadData: {
file_key: 'file',
business_id: '',
},
uploadUrl: '',
curRowIndex: null,
}
},
handleSucess(response, file, fileList){
},
handleError(err, file, fileList){
}
}
</script>
主要實現:主要實現elementui中table的行內上傳el-upload文件的操做