Vue Mixin, Axios

export default {
    data() {
        return {

    methods: {
        async callApi(method, url, dataObj) {
            try {
                return await axios({
                    method: method,
                    url: url,
                    data: dataObj
            } catch (e) {
                return e.response

Mixin to easily call api in vue js

BETA Snippet explanation automatically generated by OpenAI:

Here is what the above code is doing:
1. Import axios module
2. Create a method callApi
3. Call axios with the method, url and data object
4. Return the response

Now, we will use this code in our code.js file.


Snippet By Wamae Arnold


Created March 11th, 2022


Report Snippet