2022-11-02
2390
#vue
Ukpai Ugochi
26457
Nov 2, 2022 â‹… 8 min read

How to consume APIs with Vuex, Pinia, and Axios

Ukpai Ugochi I'm a full-stack JavaScript developer on the MEVN stack. I love to share knowledge about my transition from marine engineering to software development to encourage people who love software development and don't know where to begin. I also contribute to OSS in my free time.

Recent posts:

Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 â‹… 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 â‹… 10 min read
View all posts

8 Replies to "How to consume APIs with Vuex, Pinia, and Axios"

  1. Hi, how do you handle api errors? How are they transported to the GUI when all handling takes place in the store?

  2. Hello! I mostly use bootstrap-vue dismissible alert (https://bootstrap-vue.org/docs/components/alert). This is an example of how I use it.

    {{error}}

    export default {
    name: “Login”,
    data() {
    return {
    email: “”,
    password: “”,
    errors: [],
    };
    },
    methods: {
    login() {
    this.$store.dispatch(“retrieveUser”, {
    email: this.email,
    password: this.password
    });
    this.$store.dispatch(“retrieveId”, {
    email: this.email,
    password: this.password
    });
    this.$store
    .dispatch(“retrieveToken”, {
    email: this.email,
    password: this.password
    })
    .then(response => {
    const errors = response.data.error;
    const token = response.data.token;
    if (errors) {
    this.errors.push(errors);
    } else
    this.$router.push({
    name: “Home”
    });
    });
    },
    }

    I hope this helps!

  3. “`
    {{gettersUser.id}} {{gettersUser.name}} {{gettersUser.address}} “`
    This makes no sense. It should be getUsers.
    “`
    {{ user.id }} {{ user.name }} {{ user.address }}
    “`

  4. Hi, is there a reason that in the same file in the getters you use state.users and in the actions you use this.users? It is confusing, and not interchangeable, I tried. Actions didn’t work with state.users. Thank you

Leave a Reply