[英]Datepicker vue3 put the date in the correct format
I am using for the date "datepicker", I cannot get it back in the correct format.我正在使用日期“datepicker”,我无法以正确的格式取回它。 I have tried several different ways with the documentation, but still cannot.
我已经尝试了几种不同的方法来处理文档,但仍然不能。 Thank you for help.
谢谢你的帮助。 this is how I get the date: Sat Jun 12 2021 00:00:00 GMT+0200 (heure d'été d'Europe centrale)
这就是我获取日期的方式:Sat Jun 12 2021 00:00:00 GMT+0200(heure d'été d'Europe centrale)
<template>
<div>
<div>
<datepicker v-model="date" lang="fr" :locale="date-fns/locale/fr" type="date" :format="dd-MM-YYYY" :lowerLimit="Date.now()"></datepicker>
</div>
</div>
<template>
<script>
import Datepicker from 'vue3-datepicker'
import { ref } from 'vue'
//import { add } from 'date-fns'
const date = ref(new Date())
const dateFrom = ref(new Date())
export default {
name:'RechercheDate',
components: {
Datepicker
},
data(){
return{
date:""
}
}
}
</script>
I guess you did some small mistakes here:我猜你在这里犯了一些小错误:
Here is what your code somehow should look alike:这是您的代码在某种程度上应该看起来像的样子:
<template>
<div>
<div>
<datepicker v-model="date" lang="fr" locale="date-fns/locale/fr"
format="dd-MM-YYYY" type="date" :lowerLimit="new Date()"></datepicker>
</div>
</div>
<template>
<script>
import Datepicker from 'vue3-datepicker'
import { ref } from 'vue'
export default {
name:'RechercheDate',
components: {
Datepicker
},
setup() {
const date = ref(new Date());
return {
date,
}
}
}
</script>
What did I change?我改变了什么?
I put the date ref
into an Setup function and return it, thus you do not need the data
attribute anymore.我将日期
ref
放入 Setup function 并返回它,因此您不再需要data
属性。 you did initalize a dateFormat, but didn't use it, If you want to you need to change format
to :format="dateFormat"
and add dateFormat to your setup Function (probably no ref because it won't change) and return it too.您确实初始化了 dateFormat,但没有使用它,如果您愿意,您需要将
format
更改为:format="dateFormat"
并将 dateFormat 添加到您的设置 Function (可能没有参考,因为它不会改变)并返回它也。
Also.还。 the
:
infront of attributes are only needed if you want to execute Javascript in it (or use variables)只有当你想在其中执行 Javascript (或使用变量)时,才需要属性的
:
infront
Update: After checking for the doc I also need to confirm what Boussadjra Brahim already said, the format Property is called inputFormat
更新:检查文档后,我还需要确认 Boussadjra Brahim 已经说过的话,格式属性称为
inputFormat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.