element 日历修改今天为当月,上个月下个月事件处理

 

 需求如下:

1.修改右上角今天为当月

2.点击上个月下个月时切换数据。

 

代码如下:

 

复制代码
mounted() {
    // 点击上一个月
    const prevBtn = document.querySelector('.el-calendar__button-group .el-button-group>button:nth-child(1)')
    prevBtn.addEventListener('click', () => {
      var month = this.month.getMonth() + 1
      if (month < 10) {
        month = '0' + month
      }
      this.month = `${this.month.getFullYear()}-${month}`
      console.log('这是上个月', this.month)

      // 请求数据
      this.getData()
    })

    // 修改今日为当月
    var spanDoc = document.querySelector('.el-calendar__button-group .el-button-group>button:nth-child(2) span')
    spanDoc.innerText = '当月'

    // 点击下一个月
    const nextBtn = document.querySelector('.el-calendar__button-group .el-button-group>button:nth-child(3)')
    nextBtn.addEventListener('click', () => {
      var month = this.month.getMonth() + 1
      if (month < 10) {
        month = '0' + month
      }
      this.month = `${this.month.getFullYear()}-${month}`
      console.log('这是下个月', this.month)

      // 请求数据
      this.getData()
    })

  },
复制代码

 

posted @   烂笔头~  Views(1522)  Comments(0Edit  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示