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 Text on click</h3> <textarea v-model="textareaContent"></textarea> <button @click="downloadText">Download Text</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { textareaContent: 'Vue.js is a progressive JavaScript framework for building user interfaces. It allows developers to create dynamic and interactive web applications by combining declarative templates, component-based architecture, and reactive data binding. Vue.js is lightweight, flexible, and easy to integrate with existing projects.' // Default textarea content }; }, methods: { downloadText() { const text = this.textareaContent; // Get the content from the textarea // Create a new Blob object with the text content const blob = new Blob([text], { type: 'text/plain' }); // Create a temporary <a> element and set its download attribute to specify the file name const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'file.txt'; // Replace with your desired file name // Programmatically click the link to trigger the download link.click(); // Clean up the URL.createObjectURL by revoking the object URL after some time setTimeout(() => { URL.revokeObjectURL(link.href); }, 100); } } }); </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } textarea { width: 300px; height: 150px; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; resize: none; } button { padding: 10px 20px; background-color: #4caf50; color: white; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #45a049; } </style> </body> </html>