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 get form data on submit</h3> <form @submit="handleSubmit"> <div> <label for="name">Name:</label> <input type="text" id="name" v-model="formData.name" required> </div> <div> <label for="email">Email:</label> <input type="email" id="email" v-model="formData.email" required> </div> <button type="submit">Submit</button> </form> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { formData: { name: '', email: '' } }; }, methods: { handleSubmit(event) { event.preventDefault(); // Access the form data const { name, email } = this.formData; // Do something with the form data console.log('Name:', name); console.log('Email:', email); // Reset the form if needed this.formData.name = ''; this.formData.email = ''; } } }); </script> <style scoped> #app { width: 400px; margin: 0 auto; padding: 20px; } form { display: flex; flex-direction: column; } label { margin-bottom: 5px; } input[type="text"], input[type="email"] { padding: 5px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; } button[type="submit"] { padding: 10px 20px; background-color: #4caf50; color: #fff; border: none; border-radius: 4px; cursor: pointer; } button[type="submit"]:hover { background-color: #45a049; } -color: #0056b3; } </style> </body> </html>