我可以在我的所有vue组件中使用lodash _
吗?
例如:
我有如下组织的组件:
App.vue
> Parent.vue
> Child.vue
我希望我的所有组件都可以访问_
lodash,而无需在每个组件vm data
中定义
===
我也在尝试使用Mixins。它起作用了。但是结果不是像这样的_().isEmpty()
而不是_.isEmpty()
发布于 2016-06-08 14:10:08
您可以将lodash
导入每个组件:
<script>
import _ from 'lodash'
export default {
methods: {
test (value) {
return _.isEmpty(value)
}
}
}
</script>
发布于 2018-11-23 00:23:09
import _ from 'lodash'
Vue.prototype._ = _
在您的main.js文件中插入这些行,它将在您的应用程序中运行。
发布于 2016-10-12 01:02:26
您可以像这样全局导入lodash
window._ = require('lodash');
导入后,您将可以从任何位置访问_
。
https://stackoverflow.com/questions/37694243
复制相似问题