小编Dav*_*ghe的帖子

如何使用 Pinia 存储中定义的数组?

我创建了一个商店来使用用户资源,并且该商店具有一系列角色。我想做的是搜索该数组中的特定角色。我尝试使用数组函数,但它不适用于 PropType<T[]>。

import router from "@/router";
import axios from 'axios';
import { defineStore } from "pinia";
import { PropType } from "vue";
import { ApplicationConstants } from '../utils/Constants';

type Role = {
    name: string;
}

export const useUserStore = defineStore('user', {
    state: () => ({
        currentUserId: Number,
        currentUserUsername: String,
        currentUserRoles: Array as PropType<Role[]>,
        isLoggedIn: false
    }),
    getters: {
        getCurrentUserId: (state) => state.currentUserId,
        getCurrentUsername: (state) => state.currentUserUsername,
        getCurrentUserRoles: (state) => state.currentUserRoles,
        isUserLoggedIn: (state) => state.isLoggedIn,
        // hasCurrentUserRole: (state) => { return …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js pinia

2
推荐指数
1
解决办法
9780
查看次数

标签 统计

pinia ×1

typescript ×1

vue.js ×1