• of 循环 改变 对象值 对const的理解 对象的字面量 计算属性


    const arr = [{a:23,b:34},{a:123,b:134}]
    console.log(arr)
    for (let v of arr){
    console.log(v)
    const old = v.a
    v.a=old*old
    console.log(v)
    }
    console.log(arr)

    arr已经发生了改变

    场景

    微信小程序开发

    对后端接口的时间戳格式数据处理

    mpBMCwepysrcutilsutil.js
    
    
    const timestampSecondsToTime = (tmp) => {
      const t = function (i) {
        return (i < 10 ? '0' + (i) : i)
      }
      const date = new Date(tmp * 1000)
      const Y = date.getFullYear() + '-'
      const M = t(date.getMonth() + 1) + '-'
      const D = t(date.getDate()) + ' '
      const h = t(date.getHours()) + ':'
      const m = t(date.getMinutes()) + ':'
      const s = t(date.getSeconds())
      return Y + M + D + h + m + s
    }
    const convertArrObjListTimestamp = (arr, timestampKey) => {
      for (let v of arr) {
        const old = v[timestampKey]
        v[timestampKey] = timestampSecondsToTime(old)
      }
      return arr
    }
    export default {
      isInClosedInterval,
      isLogined,
      isMobilePhoneNum,
      delAllNonPrintableCharacter,
      convertArrObjListTimestamp
    }
    
    
    mpBMCwepysrcpagescloundAd.vue
    
    
       async getFeedData() {
          if (this.apiRes.AdKWPublished !== undefined) {
            if (this.pagination.total === this.apiRes.AdKWPublished.length) {
              wx.showToast({
                title: '亲我有底线',
                icon: 'loading',
                duration: 1500
              })
              return
            }
          }
          const q = {
            query: {
              uid: this.$parent.UID.uid,
              page: this.pagination.from,
              size: this.pagination.size
            }
          }
          const r = await api.getAdKWPublished(q)
          if (r === false) {
            return
          } else if (r.data.status !== 1) {
            wx.showToast({
              title: '亲暂无更多',
              icon: 'loading',
              duration: 1500
            })
            return
          }
          let arr = r.data.data
          arr = util.convertArrObjListTimestamp(arr, 'create_time')
          this.apiRes.AdKWPublished = this.apiRes.AdKWPublished ? this.apiRes.AdKWPublished.concat(arr) : arr
          this.pagination.total = r.data.count
          this.pagination.from += 1
          this.$apply()
        }
    

      

    方法: 对可读的时间格式的多样性扩展性

     暂时没有满足开闭原则

    const a={
    false :'123',
    v:567
    }
    const b=false
    a[b]

  • 相关阅读:
    JavaScript中字符串处理的一些函数
    JavaScript中的call、apply、bind方法的区别
    JavaScript中的数组与伪数组的区别
    关于字符集和字符编码那些事
    JavaScript的技巧和最佳实践
    Linux下编辑利器vim,vimrc,viminfo的高级用法
    pdo,更高的sql安全性
    Centos下cacti的安装
    nginx中的502错误
    mac下webpagetest搭建
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9721497.html
Copyright © 2020-2023  润新知