Loadsh库模块化引入

loadsh提供模块按需加载

loadsh本身提供模块化引入,可按需引入

1
2
3
4
5
6
7
// 
import { debounce } from 'loadsh'
import { throttle } from 'loadsh'

// 按需引入
import { debounce } from 'loadsh/debounce'
import { throttle } from 'loadsh/throttle'

webpack plugin 配置

通过webpack配置,按需加载所需要的模块

  • loadsh-webpack-plugin
  • babel-plugin-loadsh

结合使用,将全路径引用的loadsh自动转变为模块化按需引用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// @/util/loadsh.js 统一引入需要的loadsh方法
import _ from 'loadsh'

export default {
cloneDeep: _.cloneDeep,
debounce: _.debounce,
throttle: _.throttle,
isEmpty: _.isEmpty
}

// 注入全局 main.js
import _ from '@/util/loadsh.js'
Vue.prototype.$_ = _

// 组件使用
this.$_.debounce()

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×