Vue el-date-picker 日期组件的使用
一:显示年月
<el-date-picker v-model="selectMonth" type="month" placeholder="选择月" @change="jobSearch" value-format="yyyy-MM"></el-date-picker>
js代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <script> export default { data() { return { selectMonth: '' } }, created() { this .initData({}); }, methods: { jobSearch() { this .getJobListByMonth(); }, async initData(data) { //获取当前时间 var now = new Date(); var monthn = now.getMonth()+1; var yearn = now.getFullYear(); this .selectMonth = yearn+ "-" +monthn; this .selectUser = parseInt(sessionStorage.getItem( "userid" )); // this.getWeekJobList({ // userid: sessionStorage.getItem("userid"), // weekid: "1" // }); this .getJobListByMonth(); }, async getJobListByMonth(data) { } } } </script> |
二:选择年月日
<el-date-picker v-model="selectDay" type="date" placeholder="选择日" @change="dataSearch" value-format="yyyy-MM-dd"></el-date-picker>
js代码:
<script> export default { data() { return { selectDay:'' } }, created() { this.initData({}); }, methods: { dataSearch() { this.getListByDay(); }, async initData(data) { //获取当前时间 var now = new Date(); var monthn = now.getMonth()+1; var yearn = now.getFullYear(); var dayn = now.getDate(); this.selectDay = yearn+"-"+monthn+"-"+dayn; this.selectUser = parseInt(sessionStorage.getItem("userid")); this.getListByDay(); }, async getListByDay(data) { } } } </script>
三:显示年月日时分(秒)
<el-date-picker v-model="selectDatetime" type="datetime" placeholder="选择时间" @change="dataSearch" value-format="yyyy-MM-dd HH:mm" format="yyyy-MM-dd HH:mm"></el-date-picker>
js代码:
<script> export default { data() { return { selectDatetime:'' } }, created() { this.initData({}); }, methods: { dataSearch() { this.getListByDataTime(); }, async initData(data) { //获取当前时间 var now = new Date(); var monthn = now.getMonth()+1; var yearn = now.getFullYear(); var dayn = now.getDate(); var h = now.getHours(); var m =now.getMinutes(); var s = now.getSeconds(); this.selectDatetime = yearn+"-"+monthn+"-"+dayn+" "+h+":"+m+":"+s; this.selectUser = parseInt(sessionStorage.getItem("userid")); this.getListByDataTime(); }, async getListByDataTime(data) { } } } </script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~