1. 安装插件image-tools
npm i image-tools --save
import { pathToBase64, base64ToPath } from 'image-tools'
2. 上传图片
//选图片 chooseImage() { uni.chooseImage({ count: 100, //默认9 sizeType: ['compressed'], // 压缩图片 success: (res) => { console.log(res) res.tempFilePaths.forEach(item => { this.imageList.push({ mode: 'aspectFit', src: item }) }) } }); },
3. 转换图片
this.imageList.forEach(item => { pathToBase64(item.src) .then(base64 => { this.pictures.push(base64) }) .catch(error => {}) })