[英]How to set a maximum number of days to select using v-calendar range in vue.js?
Using vuejs vcalendar range , I want to limit the number of days the user can select.使用 vuejs vcalendar range ,我想限制用户可以选择的天数。 Do you know it there is some kind of a "maxDays" option?
你知道有某种“maxDays”选项吗? I have also tried to create a method where when the range is bigger than a certain number of days, the end date is modified to fit the maximum range.
我还尝试创建一种方法,当范围大于特定天数时,修改结束日期以适应最大范围。 The issue here that I found was that the calendar wasnt updating, even if the date object was.
我在这里发现的问题是日历没有更新,即使日期对象是。
So lets say I have in my template the following calendar:假设我的模板中有以下日历:
<v-date-picker v-model="range" is-range />
Where "range" is:其中“范围”是:
data() {
return {
range: {
start: new Date(),
end: new Date(),
},
};
}
I have a method that checks if the range is valid.我有一种方法可以检查范围是否有效。 And if it is not valid (ie when it is too big), the end date is modified:
如果它无效(即当它太大时),则修改结束日期:
if (!this.validRange) {
let startDate = this.range.start;
let endDate = new Date();
endDate.setDate(startDate.getDate() + 6);
this.$set(this.range, "end", endDate);
}
And as I said, the value range.end changes properly, but the calendar still shows the same range without updating the range.end value.正如我所说,值 range.end 正确更改,但日历仍然显示相同的范围而不更新 range.end 值。
Is there a way I can fix this?有没有办法解决这个问题? And I know other libraries can do those kind of thigs, I just want to know if it is possible with v-calendar.
而且我知道其他图书馆可以做这些事情,我只想知道 v-calendar 是否可行。 Thanks a lot for your help!
非常感谢你的帮助!
Julien于连
Here is a fiddle: https://jsfiddle.net/3vz9gy0d/2/这是一个小提琴: https : //jsfiddle.net/3vz9gy0d/2/
HTML: HTML:
<v-date-picker
v-model="range"
is-range
@input="handle_input()"
/>
</div>
JS: JS:
new Vue({
el: '#app',
data() {
return {
range: {
start: new Date(),
end: new Date().setDate(new Date().getDate() + 1),
}
}},
methods:{
handle_input(){
this.$nextTick(() => {
this.range = {
start: this.range.start,
end: new Date().setDate(this.range.start.getDate() + 6),
};
});
}
}
})
The range seems reactive when you create a new object.创建新对象时,范围似乎是被动的。 Listening to the input event and then updating the range seems to do the job.
侦听输入事件然后更新范围似乎可以完成这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.