How can vue tell if the current user can see this button?

I"m going to do this function now

clipboard.png

after each login, the backend will return the permissions of the current user to me:

"permissions": [
    "account:update",
    "account:list",
    "account:findById",
    "adveradvertiser:add"
],

I will store this data in localStore. With this "create advertiser" button, I will show it and hide it according to whether the data sent to me at the back end contains "adveradvertiser:add".

the first thing I think of is v-if, but here I don"t know how to iterate whether the permissions array contains adveradvertiser:add

<button class="btnYellow" v-if=""></button>

you don't have to store permissions in the cache, just put them in data
js

data() {
      return {
          permissions: [
                "account:update",
                "account:list",
                "account:findById",
                "adveradvertiser:add"
            ],
      }
}

html

v-if="permissions.indexOf('adveradvertiser:add') > 0?true:false "

js

data() {
      return {
          permissions: [
                "account:update",
                "account:list",
                "account:findById",
                "adveradvertiser:add"
            ],
      }
}

html

 v-if="permissions.some(p=>p==='adveradvertiser:add')"

write a method to determine whether the array contains the string adveradvertiser:add.

Menu