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 => {}) })