template:
<el-upload class="avatar-uploader" action :file-list="fileList" :limit=1 :http-request="uploadImage" list-type="picture-card" :on-remove="handleRemove">
? ? ? ? ? ? <i class="el-icon-plus avatar-uploader-icon"></i>
? ? ? ? ? </el-upload>
data(): fileList: []
script:
uploadImage(param) {
? ? ? const formData = new FormData();
? ? ? formData.append("photoInput", param.file);
? ? ? this.$api.image
? ? ? ? .image(formData)
? ? ? ? .then(res => {
? ? ? ? ? this.fileList.push({
? ? ? ? ? ? url: res.data.documentUrl
? ? ? ? ? });
? ? ? ? ? if (res.success) {
? ? ? ? ? ? this.taskdialog.img = res.data.documentUrl;
? ? ? ? ? ? this.$message({
? ? ? ? ? ? ? message: res.msg,
? ? ? ? ? ? ? type: "success"
? ? ? ? ? ? });
? ? ? ? ? } else {
? ? ? ? ? ? this.$message({
? ? ? ? ? ? ? message: res.data,
? ? ? ? ? ? ? type: "warning"
? ? ? ? ? ? });
? ? ? ? ? }
? ? ? ? })
? ? ? ? .catch(error => {
? ? ? ? ? console.log(error);
? ? ? ? });
? ? },
handleRemove(file, fileList) {
? ? ? this.fileList = [];
? ? },