什麼是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)
},