Sometimes, we want to use Lodash in all Vue component templates.
In this article, we’ll look at how to use Lodash in all Vue component templates.
How to use Lodash in all Vue component templates?
To use Lodash in all Vue component templates, we can add Lodash into Vue
‘s prototype.
For instance, we write
import _ from "lodash";
Object.defineProperty(Vue.prototype, "$_", { value: _ });
to call Object.defineProperty
with Vue.prototype
, "$_"
, and { value: _ }
to add the $_
property into Vue.prototype
.
Then we can access Lodash with this.$_
or $_
in the component methods and template respectively.
Conclusion
To use Lodash in all Vue component templates, we can add Lodash into Vue
‘s prototype.