lodash npm 或 yarn 安装。
$ npm install lodash --save
$ yarn add lodash
只要在 Vue.js类中引用库后,就可调用其方法。
实例如下
Click me as fast as you can!import _ from 'lodash'export default { methods: { throttledMethod: _.throttle(() => { console.log('I get fired every two seconds!') }, 2000) }} Click me as fast as you can!import _ from 'lodash'export default { methods: { throttledMethod: _.throttle(() => { console.log('I get fired every two seconds!') }, 2000) }} Click me as fast as you can!import _ from 'lodash'export default { methods: { throttledMethod: _.throttle(() => { console.log('I get fired every two seconds!') }, 2000) }} Click me as fast as you can!import _ from 'lodash'export default { methods: { throttledMethod: _.throttle(() => { console.log('I get fired every two seconds!') }, 2000) }}import _ from 'lodash'
export default {
methods: {
throttledMethod: _.throttle(() => {
console.log('I get fired every two seconds!')
}, 2000)
}
}
网友评论