V
V
Vladislav2022-04-07 16:01:51
Vue.js
Vladislav, 2022-04-07 16:01:51

How to properly set up casl/vue for vue?

Good afternoon.

How to install abilities correctly?
I get a list of ability strings in an array from the server, set them like this

try {
      const {data} = await this.$axios.get('abilities')
     
      this.$ability.update([
        {actions: data.data, subject: 'all'}
      ])
      }

I check It gives false I tried to install it like this
$can('role-access')

// импортировал defineAbility
try {
      const {data} = await this.$axios.get('abilities')
      
      defineAbility((can) => {
        can(data.data, 'all')
      })
      }

Doesn't work either.
Where is the mistake?

Who is experienced, tell me how best to do it, get rights with each click or save storage in the locale at the entrance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2022-04-08
@Vladddosss

It works like this.

// import { AbilityBuilder } from '@casl/ability';
const {data} = await this.$axios.get('abilities')
const { can, rules } = new AbilityBuilder();

can(data.data, 'all');

this.$ability.update(rules);

Instruction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question