Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
getters return a function in mutation vuex in vue js

I am working on a project that has already started and my problem is the following:

I have a mutation, which will render a menu, depending on whether the user has permission to access or not, this is calculated with a getter.

let menuList = [];
appRouters.forEach(item => {
  // eslint-disable-next-line no-console
  if (item.permission !== undefined) {
    let hasPermissionMenuArr = [];
    hasPermissionMenuArr = item.children.filter(child => {
      if (child.permission !== undefined) {
        //if (child.permission.includes('operator')) {
        console.log(hasPermission(child.permission))
          if (hasPermission(child.permission))  {
          return child;
        }
      } else {
        return child;
      }
    });

The code would "work" fine, but when it goes to access the getters to check if the user has permission to that menu, the getters that one returns the function it has to receive parameters, and not the value.

export const hasPermission = state => permission => {
return isGranted(state, permission);
};

here the other function of the getter

function isGranted(state, permissionName) {
  return (
    state.user !== undefined &&
    state.user.roles !== undefined &&
    state.user.roles.some(p => {
      return p.toLowerCase() === permissionName.toLowerCase();
    })
  );
}

I know that the getter is calling a third function, but even, to the hasPermission getter I have only put a return of a console.log of the permission that is passed to it, and even then it returns the function in text.

I know there is something that I do not understand

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!