Handle base64 format

This is a snippet of code taken to do the project

This is using new FileReader()

OnFileChange (e) {const files = e.target.files[0] console.log(e, 111) // // The following are the limits of the file size, and upload and open the picture after selecting the picture. If (files.size / 1024/1024 > 1.5) return this.$message. Warning (' Image size cannot exceed 1.5m ') // 3. If (files) {var fr = new fileReader () // Research object is to study three elements: Fr. ReadAsDataURL (files) fr. ReadAsDataURL (files) fr. AddEventListener (' Load ') Fr. Onload = () => {console.log(1111222, This) this.isDisabled = false}} console.log(files, 'images ')},Copy the code

2. FormData format of the picture

This is a snippet of code taken to do the project

Use the new FormData ()

const fm = new FormData() fm.append('title', this.pubForm.title) fm.append('cate_id', this.pubForm.cate_id) fm.append('content', this.pubForm.content) fm.append('state', This.pubform.state) // cover_img wants a file object fm.append('cover_img', this.file) const {data} = await reqPublishArticle(FM)Copy the code