常见业务代码总结

本文整理了Vue项目中常见的业务代码,包括处理el-tab组件折叠导致的echarts图表问题,实现过去时间段字符串函数,优雅地禁用按钮,操作确认提示以及折线图的基本配置,为日常开发提供便利。
摘要由CSDN通过智能技术生成

常见业务代码记录:

1.处理el-tab 折叠echarts 图表 bug

在这里插入图片描述

data() {
   
    return {
   
      active_name:"1",
      active: 1,
      tab_refresh:{
   
        lock1: true,
        lock2: false,
      },
    };
  },
  methods: {
   
    handleqie(val) {
   
      this.active = val;
    },

    handleTabchange(tab) {
   
      this.activeName = tab.name;
      switch (this.activeName) {
   
        case "1":
          this.switchTab("lock1");
          break;
        case "2":
          this.switchTab("lock2");
          break;
      }
    },
    //遍历对象拿值,然后IF判断
    switchTab (tab) {
   
      for (let key in this.tabRefresh) {
   
        if (tab === key) {
   
          this.tabRefresh[key] = true
        } else {
   
          this.tabRefresh[key] = false
        }
      }
    },
  },

2.取过去某段时间字符串函数

/**
 * @params  min 倒推的分钟数, back 倒退粒度 例如 (60*24, 1) 即往前倒退一天
 * @impact 处理时间格式,用于获取当前时间的前时间点(天/小时/分钟)
 */
window.giveDate = function giveDate(min, back){
   
  if (min != 60 * 24) {
   
    let ms = new Date().getTime(); //获取当前时间戳
    let ms_back = min * back * 60 * 1000; //获取 倒退 分钟数时间戳
    ms = ms - ms_back - (ms % (min * 60 * 1000));
    let d = new Date();
    d.setTime(ms);

    let getMonth =
      d.getMonth() 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值