screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.22/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Js Add Zero to Single Digit</h3> <input v-model="numInput" type="number"> <button @click="addZeroPadding">Add Zero Padding</button> <p v-if="paddedNum">{{ paddedNum }}</p> </div> <script type="module"> const app = Vue.createApp({ data() { return { numInput: null, paddedNum: null } }, methods: { addZeroPadding() { // Check if the user input is a valid number if (!isNaN(this.numInput) && this.numInput !== null) { this.paddedNum = this.addZero(this.numInput); } }, addZero(num) { return num.toString().padStart(2, '0'); } } }) app.mount('#app') </script> <style scoped> #app { background-color: #f7f7f7; padding: 20px; border: 1px solid #ccc; border-radius: 5px; } h3 { font-size: 1.5rem; margin-bottom: 10px; } input { padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 1.2rem; margin-right: 10px; } button { background-color: #3498db; color: #fff; border: none; padding: 10px; border-radius: 5px; cursor: pointer; font-size: 1.2rem; } p { font-size: 1.2rem; margin-top: 10px; } </style> </body> </html>