본문 바로가기
보드게임 긱 추천 게임
Wizard Thumbnail
BoardGameGeek 사이트에서 인기순위 상위 100개 중 랜덤 3개를 보여줍니다.
BGG
귀펀치토끼는 부서지지 않는다.
주소(D)
영웅은 공부 따원 안 한다네/뷰

[Vue3] HTML2Canvas

  <div ref="imageWrapper">
  	<div>출력하고 싶은 것</div>
  </div>
  <button @click="takeScreenshot('result')">출력하기</button>
const imageWrapper = ref(null) as any;

const takeScreenshot = (id: string) => {
  html2canvas(imageWrapper.value, {
    logging: false,
    allowTaint: true,
    scale: window.devicePixelRatio,
    // width: shareContent.clientWidth,
    // height: shareContent.clientHeight,
    scrollY: 0,
    scrollX: 0,
    useCORS: true,
    backgroundColor: '#ffffff',
  }).then((canvas) => {
    const imgUrl = canvas.toDataURL('image/png');
    const tempLink = document.createElement('a');
    tempLink.href = imgUrl;
    tempLink.setAttribute('download', id);
    document.body.appendChild(tempLink);
    tempLink.click();
    document.body.removeChild(tempLink);
    window.URL.revokeObjectURL(imgUrl);
  });
};
완료
내 컴퓨터