插件市場,搜索 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) }) }