Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config on individual request #41

Closed
liamjgm opened this issue Jan 6, 2019 · 5 comments
Closed

Update config on individual request #41

liamjgm opened this issue Jan 6, 2019 · 5 comments

Comments

@liamjgm
Copy link

liamjgm commented Jan 6, 2019

I want to update the axios config per request and hopefully do something like this

User.get({
    configProperty: configValue
}).then(response => {
    this.users = response.data;
    this.loadingUsers = false;
});

What can I do to achieve this?

@liamjgm
Copy link
Author

liamjgm commented Jan 6, 2019

In my User model I have tried...

get(config) {
    console.log(config)
    return super.get()
}

but the console log gives me undefined

@robsontenorio
Copy link
Owner

Do you mean set headers for axios request?

@liamjgm
Copy link
Author

liamjgm commented Jan 8, 2019

Yes, any axios config per request. For example I want to call the same endpoint but with different headers

User.get({
   progress: true <!--- progress true --->
}).then(response => {
    this.users = response.data;
    this.loadingUsers = false;
});

or

User.get({
   progress: false <!--- progress false --->
}).then(response => {
    this.users = response.data;
    this.loadingUsers = false;
});

@robsontenorio
Copy link
Owner

Maybe a new method headers() make sense.

@liamjgm
Copy link
Author

liamjgm commented Jan 8, 2019

This seems to be working well for me...

import { Model as BaseModel } from 'vue-api-query'

export default class Model extends BaseModel {

    // define a base url for a REST API
    baseURL () {
        return process.env.API_BASE_URL
    }

    constructor(...args) {
        args.length ? super(...args) : super()
    }

    static config (config) {
        let self = this.instance()
        self.config(config)

        return self
    }

    config (config) {
        this.config = config
        return config
    }

    // implement a default request method
    request (config) {
        Object.assign(config, this.config);
        return this.$http.request(config)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants