lodash工具库用法

lodash工具库用法

  • 一、引用
    • 二、用法

首先要明白的是lodash的所有函数都不会在原有的数据上进行操作,而是复制出一个新的数据而不改变原有数据。类似immutable.js的理念去处理。

一、引用

lodash是一套工具库,内部封装了很多字符串、数组、对象等常见数据类型的处理函数。

  import _ from 'lodash'

二、用法

//判断字符串是否是空
_.isEmpty(xxxxxx)

//判断是否是空值
_.isNull(xxxxxx)

//判断字符串是否包含
_.includes(this.selected, v)

//findIndex一个测试条件(函数)符合条件的数组第一个元素位置。
var a = ['a','s','d','f']
a.findIndex(function(d){// 测试条件为true时返回当前位置
    return d == 'd';
})

// _.filter过滤     findIndex返回该数组的索引号
 const selected = _.filter(
                this.selected,
                v => _.findIndex(this.regionWithChannelOptions[item.id], o => o.id === v) > -1
            )
            
//map遍历
 item.checkedList = this.regionWithChannelOptions[item.id]
                        .map(v => v.id)
                        .filter(v => !_.includes(this.noComfirmFlagIncomeProvinces, v))

链接: https://blog.csdn.net/qq_35414779/article/details/79077618?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2aggregatepagefirst_rank_ecpm_v1~rank_v31_ecpm-1-79077618.pc_agg_new_rank&utm_term=lodash%3B+_+from+import&spm=1000.2123.3001.4430.
链接: https://www.jianshu.com/p/79c577ae5bc6.

你可能感兴趣的:(Vue,json,javascript,前端)