A
A
Alexander Sharomet2018-07-19 16:14:38
JavaScript
Alexander Sharomet, 2018-07-19 16:14:38

How to make a global method in vuejs?

Hello.
How can I make a method in vuejs that I can call from any component?
It's just that I use the same method in several components, and in order not to write it for each, can I somehow place it in a separate file?
And what is the best way to use it?

methods: {
        getAllCategories() {
            axios.get('/api/categories')
                 .then(res => this.categories = res.data)
                 .catch(err => console.log('Error'));
        }
    }

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Argumentus, 2018-07-19
@sharomet

Use mixin https://ru.vuejs.org/v2/guide/mixins.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question