screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Download Json Data on click</h3> <button @click="downloadFile">Download</button> </div> <script type="module"> const app = new Vue({ el: "#app", methods: { downloadFile() { const data = [ { name: 'John Doe', age: 30, email: 'johndoe@example.com' }, { name: 'Jane Smith', age: 25, email: 'janesmith@example.com' }, { name: 'Alice Johnson', age: 35, email: 'alicejohnson@example.com' }, { name: 'Bob Williams', age: 40, email: 'bobwilliams@example.com' }, { name: 'Sarah Davis', age: 28, email: 'sarahdavis@example.com' } ]; const jsonData = JSON.stringify(data); const blob = new Blob([jsonData], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'data.json'; link.click(); URL.revokeObjectURL(url); } } }); </script> <style scoped> #app { text-align: center; margin-top: 20px; } button { padding: 10px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background-color: #45a049; } button:active { background-color: #3e8e41; } </style> </body> </html>