I want to give text color after two date with vue js, but I couldn't find a solution.
Example: I want to make the StartDate Today and the End Date 05.10.2021 red accordingly. but I want to do this condition with v-bind is it possible?
<tr v-for="(item, i) in attributes" :class="today ? 'greater' : 'today'">
<td>{{ today ,item.due_date | remainingday}}</td>
</tr>
export default {
data() {
return {
type: 'sales_invoices',
attributes: [],
start: new Date().toLocaleDateString,
}
},
async created() {
const res = await this.callApi('get', this.type)
if (res.status === 200) {
this.attributes = res.data.data
}
},
computed: {
today(){
const startY = new Date(this.start.split(".").reverse().join("."))
const end = new Date('05.10.2021'.split(".").reverse().join("."))
const difDays = Math.floor((startY.getTime() - end.getTime()) / (1000 * 3600 * 24))
return difDays > 0
},
},
app.js
Vue.filter('remainingday', function (startDate, endDate) {
const start = new Date(startDate.split(".").reverse().join("."))
const end = new Date(endDate.split(".").reverse().join("."))
if(start.toDateString() === end.toDateString()) {
return 'TODAY'
}
const difDays = Math.floor((start.getTime() - end.getTime()) / (1000 * 3600 * 24))
return difDays > 0
? `PAYMENT DELAYED FOR ${difDays} DAYS `
: `${difDays * -1} DAYS LEFT`
});