fix: failed to upload picture in the markdown editor (#401)

pull/403/head
Ryan Wang 2022-01-07 13:41:35 +08:00 committed by GitHub
parent 68c488916b
commit d3992406a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -43,14 +43,15 @@ export default {
} }
}, },
methods: { methods: {
handleAttachmentUpload(pos, $file) { async handleAttachmentUpload(pos, $file) {
const formdata = new FormData() try {
formdata.append('file', $file) const response = await apiClient.attachment.upload($file)
apiClient.attachment.upload(formdata).then(response => {
const responseObject = response.data const responseObject = response.data
const HaloEditor = this.$refs.md const HaloEditor = this.$refs.md
HaloEditor.$img2Url(pos, encodeURI(responseObject.path)) HaloEditor.$img2Url(pos, encodeURI(responseObject.path))
}) } catch (e) {
this.$log.error('update image error: ', e)
}
}, },
handleSaveDraft() { handleSaveDraft() {
this.$emit('onSaveDraft') this.$emit('onSaveDraft')