Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

242.[vue]vue中将html页面转为图片并且下载该图片 #242

Open
Labels
vuevue

Description

1.下载 html2canvas

npm install html2canvas

2.对应页面引入该插件

import html2canvas from 'html2canvas';
toImage() {
 html2canvas(this.$refs.imageDom, {
 backgroundColor: '#ffffff'
 }).then(canvas => {
 var imgData = canvas.toDataURL("image/jpeg");
 this.fileDownload(imgData);
 })
},
fileDownload(downloadUrl) {
 let aLink = document.createElement("a");
 aLink.style.display = "none";
 aLink.href = downloadUrl;
 aLink.download = "监控详情.png";
 // 触发点击-然后移除
 document.body.appendChild(aLink);
 aLink.click();
 document.body.removeChild(aLink);
},
<template>
	<div>
		<div class="container" ref="imageDom">hahahah</div>
		<button @click="toImage">导出</button>
	</div>
</template>
import html2canvas from 'html2canvas';
npm install html2canvas

Metadata

Metadata

Assignees

No one assigned

    Labels

    vuevue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /