Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda