elementUi在表格的某一行都有一个点击上传图片的按钮点击按钮upload组件上传图片
可以使用Element UI中的Upload组件来实现点击上传图片的功能。具体实现步骤如下:
-
在表格中添加一个列,用于展示上传图片的按钮。可以使用Element UI中的Button组件来实现。
-
在按钮的点击事件中,打开Upload组件弹窗,让用户选择要上传的图片。
-
在上传成功后,将图片的URL保存到表格数据中,以便在表格中展示图片。
以下是一个示例代码,用于在Element UI表格中实现点击上传图片的功能:
<template>
<el-table :data="tableData">
<el-table-column prop="name" label="名称"></el-table-column>
<el-table-column label="上传图片">
<template slot-scope="scope">
<el-button @click="showUploadDialog(scope.row)">上传图片</el-button>
</template>
</el-table-column>
<el-table-column label="图片">
<template slot-scope="scope">
<img :src="scope.row.imageUrl" v-if="scope.row.imageUrl" alt="图片">
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '项目1', imageUrl: '' },
{ name: '项目2', imageUrl: '' },
{ name: '项目3', imageUrl: '' },
],
uploadDialogVisible: false,
currentRow: null,
};
},
methods: {
showUploadDialog(row) {
this.currentRow = row;
this.uploadDialogVisible = true;
},
handleUploadSuccess(response) {
this.currentRow.imageUrl = response.data.url;
this.uploadDialogVisible = false;
},
},
};
</script>
<template>
<el-dialog v-model="uploadDialogVisible">
<el-upload
action="/api/upload"
:on-success="handleUploadSuccess"
:show-file-list="false"
>
<el-button slot="trigger" size="small" type="primary">选择图片</el-button>
</el-upload>
</el-dialog>
</template>
在上面的代码中,我们首先在表格中添加了一个列,用于展示上传图片的按钮。在按钮的点击事件中,我们打开了一个Upload组件的弹窗,让用户选择要上传的图片。在上传成功后,我们将图片的URL保存到表格数据中,以便在表格中展示图片。
原文地址: http://www.cveoy.top/t/topic/b7RH 著作权归作者所有。请勿转载和采集!