很多时候需要进入页面就有一个默认时间显示在页面且进页面调用接口的时间也是这个默认时间
//我们可以在created里面直接给组件赋值 created: () { //获取昨天日期 格式为“yyyy-MM-dd” let nowdate = new Date(); nowdate.setDate(nowdate.getDate() - 1); let y = nowdate.getFullYear(); let m = nowdate.getMonth() + 1 < 10 ? "0" + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1; let d = nowdate.getDate() < 10 ? "0" + nowdate.getDate() : nowdate.getDate(); let formatwdate = y + '-' + m + '-' + d; //获取前天日期 格式为“yyyy-MM-dd” let nowdate = new Date(); nowdate.setDate(nowdate.getDate() - 2); let y = nowdate.getFullYear(); let m = nowdate.getMonth() + 1 < 10 ? "0" + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1; let d = nowdate.getDate() < 10 ? "0" + nowdate.getDate() : nowdate.getDate(); let yesterday= y + '-' + m + '-' + d; //获取今天日期 格式为“yyyy-MM-dd” let nowDate = new Date(); let year = nowDate.getFullYear(); let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1):nowDate.getMonth() + 1; let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate(); let dateStr = year + "-" + month + "-" + day; //接下来就是给赋值了 this.sj[0]=formatwdate //开始时间赋值为昨天 this.sj[1]=dateStr //结束时间赋值为今天 },
接下来就差不多了 爱怎么操作怎么操作