直接贴了 我改了一丢丢
<template>
<div class="write">
<el-upload
ref="upload"
action="/img-upload"
list-type="picture-card"
:auto-upload="false"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:http-request="imgsubmit"
:before-upload="beforeImgUpload"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img ref="upload" width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
<el-button @click="submitupload" type="submit">点击上传</el-button>
</div>
</template>
<script>
export default {
data() {
return {
dialogImageUrl: "",
dialogVisible: false,
};
},
methods: {
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
beforeImgUpload(file, fileList) {
let _this = this;
let regs = /.+?(\.jpg|\.png|\.jpeg|\.gif)/g;
let isImg = regs.test(file.name);
if (!isImg) {
this.$message.error("请上传正确的图片格式");
return false;
}
},
imgsubmit(param){
let _this = this;
let formData = new FormData();
formData.append("file", param.file);
this.axios
.post("/img-upload", formData)
.then((res) => {
let type;
if (res.data.code == 200) {
_this.previewImages.push(res.data.data.catalog);
type = "success";
} else {
type = "error";
}
_this.$message({
message: res.data.error,
type: type,
});
});
},
submitupload(){
this.$refs.upload.submit();
console.log(this.$refs.upload.submit)
console.log(fileList)
}
},
};
</script>
<style scoped>
</style>
|