Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Error: please inject yourself instance like axios #81

Closed skazakovstas closed 4 years ago

skazakovstas commented 4 years ago

Good afternoon. Thanks so much for a great plugin.

Help to deal with the question. I use the generated code in VUE. When I try to access the method, I get an error in the promise ("Error: please inject yourself instance like axios").

Thanks for the help

Manweill commented 4 years ago

@skazakovstas Do you mind the settings I look at?

skazakovstas commented 4 years ago

In VUE component

` import Vue from 'vue' import axios from 'axios' import {ProjectService} from '../../index.js'

Vue.use(axios)

const instance = axios.create({
    baseURL: '/api',
    timeout: 1000,
    headers: {'X-Custom-Header': 'foobar'}
});

ProjectService.axios = instance

export default {
    data: () => ({
        all_project: [],
    }),

    mounted() {
        /**
         * Get all project on mount component
         */
        ProjectService.projectGet().then(response => {
            console.log(response.data)
            this.all_project = response.data
        })       
    }
}

`

This is 'import {ProjectService} from '../../index.js' generated from spec.json file, wich is transpile in to js.

Manweill commented 4 years ago

ProjectService.axios ? Shouldn't it be serviceOptions.axios?

skazakovstas commented 4 years ago

Yes, it worked. Thanks again.