Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
pinia: Define getters and actions in function notation

I am in the process of implementing a pinia store in function notation and am wondering how to declare the getters and actions.

Are these implemented as simple functions without distinction?

import { defineStore } from 'pinia'
import HttpService from '../services/BaseHttpService';
import { ref } from 'vue'
import { User } from '../models/user.model';

const httpService = new HttpService('/users');
    
export const useUserStore = defineStore('user', () => {
    const authedUser = ref(new User())
    const users = ref<User[]>([])

    function authed() {
        return typeof authedUser.value['@id'] === "string";
    }

    function login(data: { email: string, password: string }) {
        const http = new HttpService('/login');
        return http.post(data).then((response) => {
            authedUser.value = response
            users.value = [...users.value, response]
        })
    }

    function getter() {
        return users.value;
    }

    function action(id: number) {
        httpService.get(id).then((response) => {
            users.value = [...users.value, response]
        })
    }

    return {authedUser, users, authed, login}
})
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda