uni-app(六)生成海報圖片路徑問題


  插件市場,搜索 painter 插件,這款插件很是強大,初次使用,存在一個問題,那就是由於跨域導致的圖片路徑問題

  • 如果是存儲在服務器的圖片,需要使用 downloadFile 獲取圖片路徑,跳過跨域機制
    let that = this
    uni.downloadFile({
       url: that.img,
       success: function(res) {
           that.downloadPoster = res.tempFilePath
       },
       fail: function() {
           console.log('fail')
       }
    })

     

  • 下一步,需要用 getImageInfo 獲取圖片信息,輸出可以直接使用的路徑
    // 封裝圖片信息獲取方法 
    promisify: promise => {
       return (options, ...params) => {
           return new Promise((resolve, reject) => {
              const extras = {
                  success: resolve,
                  fail: reject
              }
              promise({ ...options, ...extras }, ...params)
           })
        }
    }
    // 輸出路徑
    getPoster() {
        let that = this
        const getImageInfo = that.promisify(uni.getImageInfo)
        Promise.all([
           getImageInfo({
              src: that.downloadPoster
           })
        ]).then(res => {
           // 最終路徑
           let path= res[0].path
           console.log(path)
        })
    }

     

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM