screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Download Image from URL</h3> <img :src="imageUrl" /> <button @click="downloadImage">Download</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { imageUrl: 'https://www.sarkarinaukriexams.com/images/post/1684086907flowers-g056203bb5_640.jpg', }; }, methods: { async downloadImage() { const blob = await (await fetch(this.imageUrl)).blob(); const url = URL.createObjectURL(blob); Object.assign(document.createElement('a'), { href: url, download: 'image.jpg' }) .click(); URL.revokeObjectURL(url); } }, }) </script> <style> #app { display: flex; flex-direction: column; align-items: center; justify-content: center; } img { width: 100%; max-width: 500px; } button { margin-top: 20px; padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 4px; cursor: pointer; } </style> </body> </html>