前端筆記 vue/js/git

Vue

vue-router

query: this.$route.query.name
params: this.$route.params.namejavascript

Git

版本回退

獲取commit hashvue

git reflog master  //查看本地master分支歷史變更紀錄 | Tower

git resetjava

git reset --hard <COMMIT_ID>
git reset --hard master@{1} // 回退至當前版本
git push origin master --force // 強行覆蓋遠程記錄

git revertios

git revert <COMMIT_ID> // 將該版本(包括該版本)以後的全部修改都回退
git add -A
git commit -am "版本回退"
git push origin master

Js

時間

時間格式轉換git

// 時間格式·兩位數
function ToDoubleDigit(num) {
  return num < 10 ? "0" + num : num;
}

// 獲取time對應的時間數據
function TimeToData(date) {
  const Y = date.getFullYear();
  const M = ToDoubleDigit(date.getMonth() + 1);
  const D = ToDoubleDigit(date.getDate());
  const h = ToDoubleDigit(date.getHours());
  const m = ToDoubleDigit(date.getMinutes());
  const s = ToDoubleDigit(date.getSeconds());
  return {
    Y,
    M,
    D,
    h,
    m,
    s
  };
}

// 返回所需時間格式
function ToTimeFormat(time, type) {
  let date; // js日期格式 getMonth()
  if (
    String(time).indexOf("-") === -1 &&
    String(time).indexOf("/") === -1 &&
    String(time).length === 10
  ) {
    // 時間戳轉化
    date = new Date(Number(time) * 1000);
  } else {
    // 文本時間格式轉化
    const stringTime = String(time).replace(/-/g, "/"); // ios格式支持問題
    date = new Date(stringTime);
  }
  const { Y, M, D, h, m, s } = TimeToData(date); // 獲取time對應的時間數據
  if (type === 1) {
    return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s;
  }
  if (type === 2) {
    const between = Date.now() / 1000 - new Date(time).getTime();
    const nowDate = TimeToData(new Date());
    const nowY = nowDate.Y;
    const nowM = nowDate.M;
    if (nowY === Y) {
      if (nowM === M) {
        if (between < 60) {
          return "剛剛";
        } else if (between < 3600) {
          return pluralize(~~(between / 60), " 分鐘前");
        } else if (between < 86400) {
          return pluralize(~~(between / 3600), " 小時前");
        } else {
          return pluralize(~~(between / 86400), " 天前");
        }
      } else {
        return M + "/" + D + " " + h + ":" + m;
      }
    }
    return Y + "/" + M + "/" + D + " " + h + ":" + m;
  }
}
相關文章
相關標籤/搜索