【发布时间】:2018-08-29 15:03:29
【问题描述】:
我遇到的第一个障碍是 Vue 中没有 document.getElementById 的简写,所以我实现了一个 function like this one。我面临的第二个障碍是恕我直言,html2canvas docs 在处理没有<!DOCTYPE html> 和<body> 的情况时非常有限。
这是我的.vuefile 中的标记摘要:
<template>
<div>
<md-layout>
<div id="capture" class='m1 '>
// more markup...
</div>
</md-layout>
</div>
</template>
这就是我尝试实现捕获功能的方式:
//Vue equivalent for document.getElementById
showCaptureRef() {
console.log(this.$refs.capture);
},
// Screen capture function
downloadVisualReport () {
let vc = this
alert("Descargando reporte visual")
html2canvas(vc.showCaptureRef).then(canvas => {
vc.document.body.appendChild(canvas)
}).catch((error) => {
console.log("Erorr descargando reporte visual")
alert("Error descargando el reporte visual")
});
},
【问题讨论】:
-
“我面临的第一个障碍是没有 document.getElementByIdin Vue 的简写”当然有。将
ref="foo"放在元素上,然后通过组件中的this.$refs.foo访问它。 -
你最终解决了这个问题吗?
-
@claudekennilol 是的,等一下,我会写答案
标签: javascript vue.js html2canvas