yarn add image-tools -D
使用
import { pathToBase64 } from 'image-tools'
btnBottom() { uni.chooseImage({ count: 6, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: function(res) {
//需要使用uni,getImageInfo获取图片的本地存储路径 uni.getImageInfo({ src: res.tempFilePaths[0], success :(path) => { console.log(path.path,'======') pathToBase64(path.path).then(base64 => { console.log(base64) }) .catch(error => { console.error(error) }) } }) } }); }