zoukankan      html  css  js  c++  java
  • vue-驼峰和下划线转换

    function getHumpLineName (s) {
      return s.replace(/_(w)/g, function (all, letter) {
        return letter.toUpperCase()
      })
    }
    
    function getUnderLineName (s) {
      return s.replace(/([A-Z])/g, '_$1').toLowerCase()
    }
    
    export function toHumpLineNameStyle (obj) {
      if (obj instanceof Array) {
        obj.forEach(function (v) {
          toHumpLineNameStyle(v)
        })
      } else if (obj instanceof Object) {
        Object.keys(obj).forEach(function (key) {
          let newKey = getHumpLineName(key)
          if (newKey !== key) {
            obj[newKey] = obj[key]
            delete obj[key]
          }
          toHumpLineNameStyle(obj[newKey])
        })
      }
    }
    
    export function toUnderLineNameStyle (obj) {
      if (obj instanceof Array) {
        obj.forEach(function (v) {
          (v)
        })
      } else if (obj instanceof Object) {
        Object.keys(obj).forEach(function (key) {
          let newKey = getUnderLineName(key)
          if (newKey !== key) {
            obj[newKey] = obj[key]
            delete obj[key]
          }
          toUnderLineNameStyle(obj[newKey])
        })
      }
    }
    
    
  • 相关阅读:
    六、springboot集成Swagger2
    五、springboot单元测试
    四、Springboot Debug调试
    三、springboot热部署
    二、springboot配置
    一、springboot入门
    SpringBoot整合RabbitMQ
    消息总线
    分布式配置
    路由网关---zuul
  • 原文地址:https://www.cnblogs.com/bonus_scene/p/15024726.html
Copyright © 2011-2022 走看看