第一步:安装html2canvas依赖
npm install html2canvas --save-dev
第二步:引入网页转为图片方法
import html2canvas from 'html2canvas';
第三步:使用网页转为图片方法
this.$nextTick(async () => {
const canvas = await html2canvas(元素, {
useCORS: true // 使用跨域
});
});
如果需要把图片下载下来需要配合saveAs一起来用;