Vue / Buefy的Datepicker组件选择了错误的日期

时间:2018-06-11 13:57:44

标签: javascript vue.js datepicker vuejs2 buefy

我在页面上的表单中使用Vue / Buefy作为日期选择器(第2步)https://waytorussia.net/Services/VisaSupport/Tourist.html

有时只会错误地选择出生日期:例如,用户选择1975年6月5日,但记录的数据是1975年6月6日或1975年6月4日。

我们认为问题发生在服务器上,所以我们这样做是为了让选择的日期作为字符串传输(以确保没有变化),但现在我们认为问题出在Vue中(特别是有报道称datepicker组件有这个bug。)

我们尝试过更改

Datepicker组件中的

getDategetUTCDate,但这并不能解决问题。

你对它有任何经验,或者你知道在哪里看?

1 个答案:

答案 0 :(得分:1)

我根据下面的脚本添加了date-formatter属性,它似乎工作正常。

<template>
    <b-field label="Select a date">
        <b-datepicker
            v-model="date"
            placeholder="Click to select..."
            icon="calendar-today"
            :date-formatter="formatter">
        </b-datepicker>
    </b-field>
</template>

<script>
export default {
    name: 'App',
    data() {
        return {
            date: new Date()
        }
    },
    methods: {
        formatter (d) {
            return d.toLocaleDateString()
        }
    }
}
</script>

按照示例链接:

https://codepen.io/jeanfsantos/pen/mKMBOv

我希望这会对你有所帮助。