-
-
Save Sovai/279abcf52ff471aeacce4e30a5f2eced to your computer and use it in GitHub Desktop.
global helpers helper functions #vue
This file contains 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 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 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 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