Actions — synchronous or async. Mutations — not in Pinia.
Pinia actions:
1import { defineStore } from "pinia"23export const useUserStore = defineStore("user", {4 state: () => ({ name: "", loading: false }),5 actions: {6 // Synchronous7 setName(name) {8 this.name = name9 },10 // Asynchronous11 async fetchUser() {12 this.loading = true13 const res = await fetch("/api/user")14 this.name = await res.json()15 this.loading = false16 }17 }18})
Vuex comparison: