如何在Vuejs中比较日期?

时间:2018-08-10 22:18:54

标签: javascript vue.js

嗨,我正在尝试制作一个图书馆/图书跟踪应用程序,该应用程序可以跟踪日期并返回其返回或丢失等状态。我需要在应用程序中比较日期,但是我无法在vuejs中找到方法您请帮忙谢谢。

<html>
<head>
    <meta charset=utf-8>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="newVue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="message" required placeholder="Enter Name">
        <input type="date" v-model="enterdate" placeholder="Enter Date">
        <table border="1" v-for="item in items">
            <tr>
                <td>{{item.name}}</td>
                <td>{{item.date}}</td>
            </tr>
        </table>
        <button @click="addRow">Add</button>
    </div>
</body>

window.addEventListener('load',()=>{
window.vue = new Vue({
    el: '#app',
    data: {
        message:'',
        enterdate:'',
        items:[{
            name:'',
        }]
    },
    methods: {
        addRow() {
            this.items.push({
                name: this.message,
                date: this.enterdate,


           })
        },
    }
})

})

1 个答案:

答案 0 :(得分:0)

好像您将日期表示为字符串。然后要进行比较,您需要先对其进行解析。我建议您为此使用一些现有的库。 http://momentjs.com/是一个很好的例子。

然后您将执行以下操作:

# if you copy/paste this into RStudio, there's an arrow on the margin to
# compact the ---- as if it's in brackets like {}
f <- function() {
      # extract elements to faut.laut.df -----
}