首页 > 编程知识 正文

vue怎样下拉选择一天时间段,vue中子组件有生命周期函数吗

时间:2023-05-03 10:05:21 阅读:204718 作者:2659

一、在方法中写入以下代码: methods: { getDay (day, hours) { var today = new Date() var targetday = today.getTime() + 1000 * 60 * 60 * 24 * day + hours today.setTime(targetday) var tYear = today.getFullYear() var tMonth = today.getMonth() var tDate = today.getDate() var getHours = today.getHours() tMonth = this.doHandleMonth(tMonth + 1) tDate = this.doHandleMonth(tDate) return tYear + '-' + tMonth + '-' + tDate + '小时:' + getHours }, doHandleMonth (month) { var m = month if (month.toString().length === 1) { m = '0' + month } return m }, } 二、测试: mounted () { console.log('昨天:', this.getDay(-1, 7200000)) console.log('今天:', this.getDay(0, 3600000)) console.log('明天:', this.getDay(1, 3600000)) console.log('一周后:', this.getDay(7, 7200000) }

效果:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。