vue-lodash
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

vue-lodash

NPM Known Vulnerabilities GitHub license

A small wrapper for integrating lodash to Vuejs (Inspired by vue-axios plugin)

Install

npm install --save vue-lodash lodash

Usage

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'
 
// name is optional
Vue.use(VueLodash, { name: 'custom' , lodash: lodash })
 
new Vue({
  el: '#app',
  methods: {
    test() {
      console.log(this.lodash.random(20))
      console.log(this._.random(20))
      console.log(this.custom.random(20))
    },
  }
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log(Vue.custom.random(20))

Typescript

Using custom name with typescript is currently unsupported without casting.

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'
 
Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })
 
new Vue({
  el: '#app',
  methods: {
    testLodash() {
      console.log(this.lodash.random(20))
      console.log(this._.random(20))
      console.log((this as any).custom.random(20))
    },
  }
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log((Vue as any).custom.random(20))

Tree shaking with lodash

Only import the packages you need, note that lodash tree shaking has to do import with path to module.

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import random from 'lodash/random'
import map from 'lodash/map'
 
Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })

Readme

Keywords

Package Sidebar

Install

npm i vue-lodash

Weekly Downloads

15,593

Version

2.1.2

License

MIT

Unpacked Size

7.13 kB

Total Files

6

Last publish

Collaborators

  • ewocker