小程序长按图片保存功能

wxml部分

   

js部分

 downloadImg() { //下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径
            var _this = this
            wx.downloadFile({
                url: _this.popImg,
                success (res) {
                    wx.saveImageToPhotosAlbum({  // 下载成功后再保存到本地
                        filePath: res.tempFilePath,  //返回的临时文件路径,下载后的文件会存储到一个临时文件
                        success () {
                            _this.sharePop = !_this.sharePop
                            wx.showToast({
                                title: '图片保存成功',
                                icon: 'none',
                                duration: 2000
                            })
                        }
                    })
                }
            })
        },

你可能感兴趣的:(小程序篇)