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 Change Text filed Color conditionally</h3> <input type="text" v-model="userInput" :style="{ color: textColor }"> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { userInput: '', }; }, computed: { textColor() { // Add your validation logic here // For example, check if the input is empty or doesn't meet certain criteria return this.userInput === '' || this.userInput.length < 5 ? 'red' : 'black'; }, }, }); </script> <style scoped> #app { margin: 20px; font-family: Arial, sans-serif; } h3 { margin-bottom: 10px; color: #333; } input[type="text"] { padding: 10px; width: 250px; border: 1px solid #ccc; border-radius: 5px; font-size: 14px; } </style> </body> </html>