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 Timestamp on a change event in a Dropdown menu</h3> <div class="dropdown"> <select v-model="selectedValue" @change="updateTimestamp"> <option value="">Select an option</option> <option value="Vue Js">Vue Js</option> <option value="React Js">React Js</option> <option value="Angular Js">Angular Js</option> </select> </div> <div class="timestamp-container" v-if="timestamp">Selected at: {{ timestamp }}</div> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { selectedValue: '', timestamp: null }; }, methods: { updateTimestamp() { const now = new Date(); const dateOptions = { year: 'numeric', month: 'short', day: 'numeric' }; const timeOptions = { hour: 'numeric', minute: 'numeric', second: 'numeric' }; const formattedDate = now.toLocaleDateString(undefined, dateOptions); const formattedTime = now.toLocaleTimeString(undefined, timeOptions); this.timestamp = `${formattedDate} ${formattedTime}`; } } }); </script> <style> #app { 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); width: 600px; margin: 0 auto; padding: 20px; } .dropdown { position: relative; display: inline-block; } .dropdown select { padding: 8px 16px; font-size: 14px; border: 1px solid #ccc; border-radius: 4px; background-color: #fff; color: #333; } .timestamp-container { margin-top: 10px; font-size: 16px; font-weight: bold; } /* Style the selected option */ .dropdown select option:checked { background-color: #f0f0f0; } </style> </body> </html>