Skip to content

Files对象转base64

记录一段使用wangEditor3时自定义上传图片的代码

后端需要base64数据,查找之后,这种方法还算是简洁

js
this.editor.customConfig.customUploadImg = (files, insert) => {
    let reader = new FileReader()
    reader.readAsDataURL(files[0])
    reader.onload = e => {
        let url = `xxx`
        let baseData = e.target.result
        axios.post(url, { data: baseData })
            .then(({ data: resData }) => {
                let { data, status } = resData
                insert(data["image_url"])
        })
    }
}