screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h2>Vue Js Get name from email address</h2> <ul> <li v-for="email in emails" :key="email"> <strong>{{ email }}</strong> - {{ extractNameFromEmail(email) }} </li> </ul> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { emails: [ "john.doe@example.com", "jane.smith@example.com", "mark.johnson@example.com", "sarah.williams@example.com", "michael.brown@example.com", "emily.davis@example.com", "david.jones@example.com", "jennifer.jackson@example.com", "alexander.white@example.com", "olivia.anderson@example.com", ], }; }, methods: { extractNameFromEmail(email) { const [firstName, lastName] = email .split("@")[0] .split(".") .map((name) => name.charAt(0).toUpperCase() + name.slice(1)); if (lastName) { return `${firstName} ${lastName}`; } else { return firstName; } }, }, }); </script> <style> #app { margin: 0 auto; width: 600px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } /* Style for the heading */ h2 { color: #333; margin-bottom: 20px; } /* Style for the unordered list */ ul { list-style-type: none; padding: 0; } /* Style for each list item */ li { margin-bottom: 10px; padding: 10px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } /* Style for the email address */ strong { color: #333; } /* Style for the extracted name */ .extracted-name { color: #666; } </style> </body> </html>