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