美文网首页
开发图库管理遇到的问题

开发图库管理遇到的问题

作者: 陈老板_ | 来源:发表于2019-11-28 20:22 被阅读0次

    处理时间戳为日期格式

    transDate (n) {
          let date = new Date(n);
          let Y = date.getFullYear() + '-';
          let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
          return (Y + M + D)
        }
    

    对象数组分组

    // 根据时间进行数据分组,分组格式push到dest中,如果存在相同字段,则在相应data数组中push操作
    let map = {};
    let dest = [];
          for(let i = 0; i < this.imageList.length; i++){
              var ai = this.imageList[i];
              if(!map[ai.hex_create_time_stamp]){
                dest.push({
                  time: ai.hex_create_time_stamp,
                  data: [ai]
                });
                map[ai.hex_create_time_stamp] = ai;
              }else{
                for(let j = 0; j < dest.length; j++){
                  let dj = dest[j];
                  if(dj.time == ai.hex_create_time_stamp){
                    dj.data.push(ai);
                    break;
                  }
                }
              }
            }
    

    map方法使用

    map可对数组每一项进行操作,而且不能中途终止,return也不行
    为什么不用forEach,比map速度快,但是fetch更适合不对数组进行修改适合使用
    forEach()方法不会返回执行结果,而是undefined。也就是说,forEach()会修改原来的数组。而map()方法会得到一个新的数组并返回。

    this.imageList.map((item, index) => {
            if (item.showName.indexOf(this.searchValue) != -1) {
              this.searchArr.push(item);
            }
    })
    

    vue1.0 $set使用

    $set的参数为(index, {修改的item,修改的字段,修改的值})
    使用es6解构赋值...代表其他字段

    this.todayImageList[i].data.$set(j,{...this.todayImageList[i].data[j],'isChoose':true});
    

    localStorage使用

    setItem进行赋值 (字段名,值)

    localStorage.setItem('selectActive',this.selectImageActive);
    

    相关文章

      网友评论

          本文标题:开发图库管理遇到的问题

          本文链接:https://www.haomeiwen.com/subject/hvkiwctx.html