password: '',
confirmPassword: '',
computed: {
empty() {
return this.user.password === '' || this.user.confirmPassword === '';
},
equal() {
return this.user.password === this.user.confirmPassword;
}
}
.empty {
width: 160px;
height: 50px;
line-height: 50px;
text-align: center;
font-size: 16px;
font-weight: 600;
color: #fff;
background-color: #f68e91;
border-radius: 10px;
margin-top: 15px;
padding: 0 20px;
cursor: pointer;
opacity: 0.5;
display: flex;
justify-content: center;
align-items: center;
outline: none;
border: none;
}
.no-empty {
opacity: 1.5;
background-color: #ee1d24;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<input v-model="user.password" type="text">
<input v-model="user.confirmPassword" type="text>
<button :class="[equal && !empty ? 'empty' : 'no-empty']" :disabled="!equal || empty">Send</button>
< /div>
For the above code, I am able to change the color of the button if the fields are empty, and if filled they are not empty, changing the color.
The issue is in the confirmPassword field - if I enter a single character only, it is changing the color of the button. I need it to only change the button color if the password and confirm password match, otherwise show a different color.