uniapp 上传图片


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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM