uniapp图片保存到本地

//页面
<button type="primary" @click="saveImg">保存图片到本地</button>

//js
saveImg(){
    const that = this;
    uni.downloadFile({
        url:'图片网络路径',
        success: res => {
            if (res.statusCode === 200) {
                uni.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success: function() {
                        this.tools.toast('保存下载成功');
                    },
                    fail: function() {
                        this.tools.toast('保存失败,请稍后重试');
                    }
                });
            } else {
                this.tools.toast('下载失败');
            }
        }
    });
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐