安装

$ npm i --save lodash

在vue中注册

//plugins/lodash
const groupBy = require('lodash/groupBy')
const cloneDeep = require('lodash/cloneDeep')
const max = require('lodash/max')
const min = require('lodash/min')
const flatten = require('lodash/flatten')
const throttle = require('lodash/throttle')
const debounce = require('lodash/debounce')
global._ = {
    groupBy,
    cloneDeep,
    max,
    min,
    flatten,
    throttle,
    debounce
}

let lodash = {}
lodash.install = function(Vue, options) {
    Vue.prototype._ = global._
}
export default lodash


.groupBy(collection, [iteratee=.identity]

  1. 参数
collection (Array Object): 一个用来迭代的集合。
[iteratee=_.identity] (Array Function Object string): 这个迭代函数用来转换key。
  1. 例子 ``` _.groupBy([6.1, 4.2, 6.3], Math.floor); // => { ‘4’: [4.2], ‘6’: [6.1, 6.3] }

// The _.property iteratee shorthand. _.groupBy([‘one’, ‘two’, ‘three’], ‘length’); // => { ‘3’: [‘one’, ‘two’], ‘5’: [‘three’] }

_.groupBy(this.shoes, (item)=>item.color)


### _.throttle
一段时间内只执行一次

_.throttle(func, [wait=0], [options=])#

func (Function): 要节流的函数。 [wait=0] (number): 需要节流的毫秒。 [options=] (Object): 选项对象。 [options.leading=true] (boolean): 指定调用在节流开始前。 [options.trailing=true] (boolean): 指定调用在节流结束后。

// 元素滚动 避免频繁计算造成计算浪费 this.scroll = _.throttle(this.scroll,300)

### _.debounce
最后一次xx时间后执行

_.debounce(func, [wait=0], [options=])#

func (Function): 要防抖动的函数。 [wait=0] (number): 需要延迟的毫秒数。 [options=] (Object): 选项对象。 [options.leading=false] (boolean): 指定在延迟开始前调用。 [options.maxWait] (number): 设置 func 允许被延迟的最大值。(类似节流) [options.trailing=true] (boolean): 指定在延迟结束后调用。

// 元素滚动 停止后300ms才计算 this.scroll = _.throttle(this.scroll,300)

```