<el-button
class="file"
v-loading.fullscreen.lock="fullscreenLoading"
element-loading-text="上传中"
>
<input type="file" @change="change" />
点击上传
</el-button>
获取文件流
const change = (e: any) => {
console.log(e.target.files[0]);
// 手写的input需要一个对象将本地图片转换为对应的格式来上传
let formData = new FormData();
// e.target.files就是选中的文件的一个数组
formData.append("file", e.target.files[0]);
formData.append("type", "1");
fullscreenLoading.value = true;
api.post("/api/file/uploadImages", formData).then((res: any) => {
console.log(res);
form.value.detailsImgAndPageUrl = res.body;
fullscreenLoading.value = false;
});
};
更改原生上传样式
.file {
position: relative;
width: 100px;
background-color: #ccc;
text-align: center;
}
.file input {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
opacity: 0;
}
.file:hover {
background: #aadffd;
border-color: #78c3f3;
color: #004974;
text-decoration: none;
}