Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Vuejs global filters two params

I want to find the number of days between two dates with vue js, but I could not do it somehow.

For example,

the start will always be today, and the end date will be the date from the database.

Accordingly, I want to show the user how many days are left. if today's date has not passed the end date

  • 10 days after...
  • if today's date has passed the end date
  • 10 days late.
  • or if the dates are equal, I want TODAY to be written.

component

<p>{{'05/10/2021', '30/11/2021' | remainingday }}</p>

app.js

Vue.filter('remainingday ', function (start,end) {
    return
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try like following snippet:

new Vue({
  el: '#demo',
  data(){
    return {
      start: new Date(),
      end: new Date()
    }
  },
  filters: {
    remainingday (start, endDate) {
      const end = new Date(endDate)
      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`
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <label>Chose end date</label>
  <input type="date" v-model="end" />
  <p>{{start, end | remainingday }}</p>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

I opine this code work

Vue.filter('remainingday', function (value,start,end) {
   return value.match(start)
})



<p>{{ '' | remainingday('05/10/202','30/11/2021') }}</p>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda