Element UI 上传图片获取路径:on-success 事件使用指南
您可以使用on-success事件来获取上传成功的图片路径。在上传成功后,Element UI 会触发on-success事件,并将上传成功的文件信息作为参数传递给事件处理函数。您可以在事件处理函数中获取文件的路径。
以下是一个示例代码:
<template>
<el-upload
action="/upload"
:on-success="handleSuccess"
>
<el-button slot="trigger" size="small" type="primary">点击上传</el-button>
</el-upload>
</template>
<script>
export default {
methods: {
handleSuccess(response, file, fileList) {
// response为服务器返回的响应数据
// file为当前上传的文件对象
// fileList为上传成功的文件列表
console.log(response.path); // 输出上传成功的图片路径
}
}
}
</script>
在上述示例中,handleSuccess方法会在上传成功后被调用,response参数即为服务器返回的响应数据,您可以从中取出上传成功的图片路径。
原文地址: https://www.cveoy.top/t/topic/pZQ6 著作权归作者所有。请勿转载和采集!