Last active
January 17, 2023 21:29
-
-
Save vielhuber/afcb99fdf23febffe0199649e19642cb to your computer and use it in GitHub Desktop.
global helpers helper functions #vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div :test="$helpers.foo1()" :test2="bar()"></div> | |
</template> | |
<script> | |
import { bar } from '@/helpers/utils'; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/helpers/utils.js | |
// these functions can be used without importing | |
export default { | |
foo() { | |
return 'foo'; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import helpers from './helpers/global'; | |
Vue.use({ | |
install() { | |
Vue.helpers = helpers; | |
Vue.prototype.$helpers = helpers; | |
} | |
}); | |
/* usage inside components: */ | |
this.$helpers.foo() | |
/* usage anywhere else: */ | |
Vue.helpers.foo() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/helpers/utils.js | |
// these functions can only be used after importing | |
function bar() { | |
return 'bar'; | |
} | |
export { bar }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot it's very helpful ! ^^