如何在Vue.js中使用lodash库

2018-07-05  本文已影响0人  630d0109dd74

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)

  }

}

上一篇 下一篇

猜你喜欢

热点阅读