Return function true returns false on a Vue expression

0

I've created a method that serves to make a difference on a particular date with today's date. With the code I put, it returns true . But when I use it inside a computed value, it returns undefined . And in the computed value I make a conditional which will anyway return true but when I use it as an expression in Vue, it returns false.

<template>
    <p v-if="dataqualquer">Hello World</p>
</template>

<script>
    computed: {
        dataqualquer() {
            const data = this.dataDiferenca("05/02/2018")
            data ? true : true
        }
    },
    methods: {
        dataDiferenca(data) {
           // console.log(data)
           // data = data.split("/")
           // data.reverse();
           // data = data.join("-")
           // data = this.moment(data)
           // console.log(data.diff())

           // data.diff() < 0 ? false : true
           data = data.split("/");
           data.reverse();
           data = data.join("-")
           data = new Date(data)

           const hoje = new Date()

           data - hoje < 0 ? false : true
        }
    }
</script>
    
asked by anonymous 27.01.2018 / 17:38

1 answer

1

You forgot to give return in your method dataDiferenca and in computed value dataqualquer

var vue = new Vue({
    el: '#app',
    computed: {
        dataqualquer () {
            const data = this.dataDiferenca("05/02/2018")
            return data
        }
    },
    methods: {
        dataDiferenca (data) {     
           data = data.split("/");
           data.reverse();
           data = data.join("-")
           data = new Date(data)

           const hoje = new Date()

           return data - hoje < 0 ? false : true
        }
    }
})
<script src="https://vuejs.org/js/vue.min.js"></script><divid="app">
    <p v-if="dataqualquer">Hello World</p>
</div>
    
27.01.2018 / 19:58