我选的是element里面上传头像的那一串代码 然后做了一点修改
<el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/" accept=".png,.jpg,.jpeg,.gif" :show-file-list="false" :on-change="showLogo">
<img v-if="addForm.logo" :src="addForm.logo" class="avatar"/>
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
validateFileSize是判断上传文件的方法,这里只用到了图片的,也可以使用element里面的
uploadPicture() {
_this.closeParentDialog();
const fileData = new FormData();
fileData.append("file", _this.imgFile);
fileData.append("picName", removeAllSpace(_this.botAddForm.picName));
uploadPicture(fileData)
.then((res) => {
_this.$message.success(_this.$t("me