The way to import a helper function into the Vuejs template
In a Vuejs app, there is a clear division between the template and script code. When you'd like to use a global function or a helper that it has imported from outside of the Vuejs file, you have to import and put it in the methods hook like the example below.
Export your helper functions:
In the scripts of Vuejs file, import your helpers and put them into the methods hook like this:
Finally, you can use the helper functions at wherever you want in the Vuejs template:
Export your helper functions:
export const helperFunctionA = (params) => { // do something } export const helperFunctionB = (params) => { // do something }
In the scripts of Vuejs file, import your helpers and put them into the methods hook like this:
import { helperFunctionA, helperFunctionB } from ‘../helper’; export default { /// your vuejs scripts code methods: { helperFunctionA, helperFunctionB, otherMethod(){ // do something } } }
Finally, you can use the helper functions at wherever you want in the Vuejs template:
Latest
Related
© 2019 4codev
Created with love by Sil.