Vue上线收集错误信息

Vue.config.errorHandler = function(err, vm, info, a) {
  Vue.nextTick(() => {
    for(let i=0;i < localStorage.length; i++){
      let key = localStorage.key(i);
      if(new Date().getTime() - new Date(key).getTime() > 2*24*3600*1000) {
        localStorage.removeItem(key)
      }
    }
    let date = new Date();
    let time = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()
    let error = {
      name: err.name,
      message: err.message,
      stack: err.stack
    }
    localStorage.setItem(time, JSON.stringify(error));
  })
}

上一篇:Cookie、session和localStorage、以及sessionStorage之间的区别


下一篇:vue3.0里全局封装axios