小工具知识网

当前位置: 首页 > 行业知识 > 跨平台应用开发进阶(五十三):uni-app 通过webview方式嵌套H5实现图片点击下载

行业知识

跨平台应用开发进阶(五十三):uni-app 通过webview方式嵌套H5实现图片点击下载

2026-11-12 04:19:26 来源:互联网转载

signShare() {
this.toImage();
},
toImage() {
Toast.loading();
const node = this.$refs.luckyInfo;
htmlToImage(node, 2).then(img => {
this.shareObject.image = img;
// launchSharePanelPic(this.shareObject);
// 展示海报
this.showPicNewyear(this.shareObject.image, this.shareObject.title);
// this.goPage();
Toast.hide();
}).catch(err => {
console.log(err);
Toast.hide();
})
},

其中,`htmlToImage`为利用`html2canvas`方法将页面`html`转换为`base64`。

// 利用html2canvas将页面html转换为base64
export function htmlToImage(node, ratio = 16/9) {
// 获取像素比
const scale = getDPR();
let canvasOptions = document.createElement(“canvas”);
canvasOptions.width = window.innerWidth * scale;
canvasOptions.height = window.innerWidth * ratio * scale

上一篇:易语言数字热键设置教程,一键实现数字热键功能轻松操作

下一篇:云服务器天气推送怎么关闭?