在node_modules=>vant=>es=>datetime-picker文件夹index.js中
找到 三处 year-month 在分别在下面添加
//1.
if (this.type === 'year') result.splice(1, 4);
//2.
if (this.type === 'year') {
month = 1
date = 1;
}
//3.
if (this.type === 'year') {
values = values.slice(0, 1);
}
使用
<van-datetime-picker
v-model="currentDate"
type="year"
/>
本文介绍如何在Van项目的DateTimePicker组件中进行代码修改,以支持仅选择年份的功能。通过在index.js文件中添加特定条件判断,可以实现在选择年份时隐藏月份和日期的选择,提供了一个简洁的年份选择界面。
1677

被折叠的 条评论
为什么被折叠?



