How can one use a function imported from another script in a vue component?

If you are developing multiple components in Vue, you might be facing the situation that you have the following folder structure: . โ””โ”€โ”€ src/ โ””โ”€โ”€ components/ โ”œโ”€โ”€ utils/ โ”‚ โ””โ”€โ”€ some_cool_functions.js โ”œโ”€โ”€ component_a.vue โ””โ”€โ”€ component_b.vue $ cat some_cool_functions.js export function function_b(id) { console.log("Do some stuff in function a " + id) } export function function_b(id) { console.log("Do some stuff in function b " + id) } <template> <div> .... <v-btn @click="function_a(item.id)" color="error">Some Button for Function A</v-btn> <v-btn @click="function_b(item.id)" color="error">Some Button for Function B</v-btn> </div> </template> <script> import { function_a, function_b } from './functions/some_cool_functions.js' export default { components: { }, setup() { }, data() { return { some_value: '' }; }, methods: { function_a, // <-- add this function_b, } } </script> Then you have a button in component_a.vue which would like use the function from utils script. Then you need to do the following: ...

November 30, 2023 ยท 1 min ยท Moritz Gnisia