0
点赞
收藏
分享

微信扫一扫

2022知识点小记

炽凤亮尧 2022-03-11 阅读 65
npmvue.jsui
  1. vant 单元格样式
vant 方框
    background: #ffffff;
    margin: 10px 10px 0 10px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: 0 0 3px 3px #eeeeee;
    box-shadow: 0 0 3px 3px #eeeeee;
  1. 递归获取想要的数据结构
    // 递归
    convertTree(tree) {
      const result = []
      // 遍历 tree
      tree.forEach((item) => {
        // 解构赋值
        let { id: value, name: label, children: children } = item

        // 如果有子节点,递归
        if (children) {
          children = this.convertTree(children)
        }

        result.push({
          value,
          label,
          children,
        })
      })

      return result
    },

3.造数据随机生成数字

// 生产GUID
const creatGuid = () => {
  return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
    var r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8
    return v.toString(16)
  })
}

// 随机生成随机整数
const randomFloor = (min, max) => {
  return Math.floor(Math.random() * (max - min)) + min
}

4.时间格式化

const timeFormatter = (value, type) => {
  var date = value
  var seperator1 = "-"
  // var seperator2 = ":"
  var month = date.getMonth() + 1
  var strDate = date.getDate()
  if (month >= 1 && month <= 9) {
    month = "0" + month
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate
  }
  // 年月日
  if (type == "YYYY-MM-DD") {
    value = date.getFullYear() + seperator1 + month + seperator1 + strDate
  }

  // 年月
  if (type == "YYYY-MM") {
    value = date.getFullYear() + seperator1 + month
  }
  return value
}
举报

相关推荐

ibaits知识点

Less知识点

jquery知识点

Hadoop知识点

CSS知识点

0 条评论