element-ui的tab切换。当前时间如果在某个时间段内,就默认选中

 

   <el-tabs type="border-card" v-model="activeName">
        <el-tab-pane v-for="item in eltab" :key="item.index">

 

          if (res.data.planList.length > 0) {
            let nowT = moment(new Date()).format('YYYY-MM-DD HH:mm')
            this.eltab.forEach((item, index) => {
              this.checkTime(item.start_time, item.end_time, nowT)
              // 如果在范围内 找下标
              if (this.times == true) {
                this.activeName = index + ''
              }
            })
          }

 

 

   //判断当前时间是否在时间段内
    checkTime(stime, etime, ntime) {
      //开始时间
      let startTimes = moment(stime).format('x')
      //结束时间
      let endTimes = moment(etime).format('x')
      //当前时间
      let nowTimes = moment(ntime).format('x')
      if (nowTimes > startTimes && nowTimes < endTimes) {
        this.times = true
      } else {
        this.times = false
      }
    },

 

posted on 2022-12-08 10:22  一往而深のcode  阅读(326)  评论(0编辑  收藏  举报