In this article, we will learn how to use dom-to-image-more in vue.js
Step 1: Create new Vue project:
npm create dom-to-image-more-demo
Step 2: Install require packages:
npm i dom-to-image-more
Step 3: Open App.vue file and add following in it:
<template> <div id="template-for-print"> <img alt="Vue logo" src="./assets/logo.png" /> <HelloWorld msg="Welcome to Your Vue.js App" /> </div> </template> <script> import domToImage from "dom-to-image-more"; import HelloWorld from "./components/HelloWorld.vue"; export default { name: "App", components: { HelloWorld, }, mounted() { this.imageGenerate(); }, methods: { imageGenerate() { domToImage .toSvg(document.getElementById("template-for-print")) .then((dataUrl) => { const div = document.createElement("div"); div.className = "output"; const img = document.createElement("img"); img.src = dataUrl; div.appendChild(img); document.body.appendChild(div); }); }, }, }; </script> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .output { border: 2px solid red; border-radius: 1rem; } </style>
Output: