GithubHelp home page GithubHelp logo

vue-cancan's People

Contributors

dalezak avatar sandrew avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-cancan's Issues

Vue3 Support To Replace prototype With globalProperties

Looks like Vue3 no longer supports prototype now requires using globalProperties instead.

https://v3.vuejs.org/guide/migration/global-api.html#vue-prototype-replaced-by-config-globalproperties

In Vue 2, Vue.prototype was commonly used to add properties that would be accessible in all components.The equivalent in Vue 3 is config.globalProperties. These properties will be copied across as part of instantiating a component within the application.

Any plans or suggestions how to make vue-cancan work with Vue3?

Cannot read property 'rules' of undefined

I'm having problems getting vue-cancan to work in my Rails 6 + Vue app. ๐Ÿ˜ž

Initially I was getting stack level too deep when calling current_ability.to_json.html_safe.

So implemented as_json in ability.rb as suggested in the readme.

def as_json(options = {})
  rules.map do |rule|
    {
      base_behavior: rule.base_behavior,
      actions: rule.actions.as_json,
      subjects: rule.subjects.map(&:to_s),
      conditions: rule.conditions.as_json
    }
  end
end

This got rid of the stack level too deep error.

<script>
window.abilities = <%= current_ability.to_json.html_safe %>
</script>

However started getting Cannot read property 'rules' of undefined from this line

Vue.use(VueCanCan, { rules: window.abilities.rules });

This is what the inline JSON looks like

window.abilities = [{"can":true,"base_behavior":true,"actions":["manage"],"subjects":["User"],"conditions":{}},{"can":true,"base_behavior":true,"actions":["manage"],"subjects":["Note"],"conditions":{}}]

Should the JSON embed code just be?

Vue.use(VueCanCan, { rules: window.abilities });

Or is the structure of my as_json method wrong?

Rewrite to use CASL?

Hi there,

I'm just wondering whether you would like to use casl to achieve your goals.

This library implements cancan for JavaScript in isomorphic way + a bit more.

this will allow to close all your TODOS :)

Also a while ago there were published 2 articles about Vue and Casl. I think it's worth to check out:

I'm the author of this library, so feel free to ask questions if any.

Looking forward for productive collaboration!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.