@okvue/vue-fetch

0.2.19 • Public • Published

vue-fetch

simple data fetch for vue(x)

use with vuex

how to use

import vuefetch from "@okvue/vue-fetch"
Vue.use(vuefetch)

// config for fetch client
new Vue({
    fetch: {
        backend: 'https://path/to/api',
        api: {
            repos: 'repos',
            projs: 'projects'
        }
    }
    ...
})

// in vue component
export default {
    created() {
        this.$fetch('repos').then(data => {
            // todo with data
        });
    }
};

feature

fetch options

new Vue({
    fetch: {
        method: 'post',
        headers: {
            "content-type": "javascript/json"
        }
        ...
    }
    ...
})

or

export default {
    created() {
        this.$fetch('repos', {
            method: 'post',
            headers: {
                "content-type": "javascript/json"
            }
            ...
        }).then(data => {
            // todo with data
        });
    }
};

multiple fetch

export default {
    created() {
        this.$fetch(['repos', 'projs']).then(data => {
            // todo with data
        });
    }
};

fetch status

export default {
    created() {
        this.$fetch('repos').then(data => {
            // todo with data
        });
    }
    // you can use computed or just use {{this.$store.getters.repos}}
    computed: {
        reposStatus(){
            return this.$store.getters.repos
        }
    }
};

query

export default {
    created() {
        this.$fetch({
            url: 'repos',
            query: {
                author: 'owcc'
                ...
            }
        }).then(data => {
            // todo with data
        });
    }
};

post data

not allow to multiple post for now

export default {
    created() {
        this.$fetch('repos', {
            name: 'name',
            other: 'other'
        }).then(data => {
            // todo with data
        });
    }
};

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.190latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.190
0.2.180
0.2.170
0.2.160
0.2.150
0.2.140
0.2.130
0.2.120
0.2.110
0.2.100
0.2.90
0.2.80
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.90
0.1.80
0.1.70
0.1.60
0.1.50
0.1.40
0.1.30
0.1.20

Package Sidebar

Install

npm i @okvue/vue-fetch

Weekly Downloads

0

Version

0.2.19

License

ISC

Unpacked Size

66 kB

Total Files

10

Last publish

Collaborators

  • ow