hinesboy / mavonEditor

mavonEditor - A markdown editor based on Vue that supports a variety of personalized features
http://www.mavoneditor.com/
MIT License
6.45k stars 918 forks source link

$imgDel使用file作为参数 #460

Open u-sho opened 5 years ago

u-sho commented 5 years ago

Issue

There is a difference between documents and actual implementation of $imgDel function.

Detail

I checked the params of $imgDel(params) with console.log(params) .
Documents says that the imgDel function is given String: filename . However, the params was an array like this.

[filename, FILE]

So, it is needed to fix document or to change implementation.

To Resolve

Target File

Samples

README

|imgDel | String: filename, File: imgfile | 图片文件删除回调事件(filename: 写在md中的文件名, File: File Object) |

upload-image

        $imgDel(pos){
            delete this.img_file[pos[0]];
                                  // ^changed
        }
u-sho commented 5 years ago

This is my Nuxt.js code to check params.

<template>
    <mavon-editor
        ref="md"
        v-model="markdownText"
        @imgAdd="addImage"
        @imgDel="deleteImage"
    />
</template>
<script>
import 'mavon-editor/dist/css/index.css'
export default {
    data() {
        return {
            markdownText: '',
            imageFiles: []
        }
    },
    methods: {
        addImage(filename, file) {
            this.imageFiles[filename] = file
        },
        deleteImage(filename) {
            console.log(filename) // check this param 
            delete this.imageFiles[filename]
        }
    }
}
</script>

and here is one of the results

(2) [1, File, __ob__: Observer]
    0: 1
    1: File {miniurl: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD…lnjvFL/8AHKhuP2gvEEkmW0/SWOMcwyf/AByq5GDeuh//2Q==", _name: "u_sho.jpeg", name: "u_sho.jpeg", lastModified: 1549678985750, lastModifiedDate: Sat Feb 09 2019 11:23:05 GMT+0900 (日本標準時), …}
    length: 2
    __ob__: Observer {value: Array(2), dep: Dep, vmCount: 0}
    __proto__: Array
u-sho commented 5 years ago

Thanks to this npm package, my work is going successful.
I pray for further improvement of this repository 😸