什么是Lodash?
Lodash是一个一致性、模块化、高性能的 JavaScript 实用工具库。
Lodash 消除了处理数组的麻烦,从而简化了 JavaScript、 数字、对象、字符串等。
它的模块化方法非常适合:
-
迭代数组,对象和字符串
-
操作和测试值
-
创建复合功能
如何在vue中使用Lodash 、
首先 npm i lodash -S
其次在main.js 中
import _ from 'lodash'
Vue.prototype._ = _;
然后 在其他组件中就可以使用了 例如在created中使用
created: function() {
// `_.debounce` 是一个通过 Lodash 限制操作频率的函数。
this.debouncedGetAnswer = this._.debounce(this.getAnswer, 1000)
},