【JavaScript笔记】如何快速设置Object多维对象的某个属性或值

前端在部分业务下会有一种场景,需要修改某个对象单独的属性或值且修改后立即生效(如页面缓存、样式布局DIY调整配置),当这个对象是3维或者3维以上时,且传参的数据不一致,如果配置项较多,死方法就是每个对象都去一遍(比较愚蠢的写法)这个时候的代码量就比较多,那么如何减少这个代码量呢??下面我就写了一个函数,可以通过固定代码即可达到减少代码量const setValue = function(data, key, value) {    if ('object' !== typeof data) {        return null    }    if (key.indexOf('.') > 0) {        let index1 = key.split('.')[0];        let index2 = key.replace(new RegExp('^' + index1 + '\.', 'g'), '');        if (data.hasOwnProperty(index1)) {            data[index1] = setValue(data[index1], index2, value);        }        return data;    } else {        if (data.hasOwnProperty(key)) {            data[key] = value        }        return data    }}

【vue笔记】运行npm install or npm update 报错 path git errno -4058

运行npminstall报错解决方法npm ERR! code ENOENTnpm ERR! syscall spawn gitnpm ERR! path gitnpm ERR! errno -4058npm ERR! enoent Error while executing:npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/sohee-lee7/Squire.gitnpm ERR! enoentnpm ERR! enoentnpm ERR! enoent spawn git ENOENTnpm ERR! enoent This is related to npm not being able to find a file.npm ERR! enoentnpm ERR! A complete log of this run can be found in:npm ERR! D:\node\node_cache_logs\2020-09-01T01_09_19_309Z-debug.log

作者信息

最近发表

最新留言

文章归档

«    2022年6月    »
12345
6789101112
13141516171819
20212223242526
27282930

目录[+]