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