Vue-acl is a plugin designed for Vue.js 2 applications to manage user access permissions for components and routes. It provides a structured way to define global and local access rules using a fluent API (`AclRule`) with `or` and `and` conditions. The package, currently at version 4.1.10, facilitates integrating an Access Control List (ACL) system by allowing developers to specify initial permissions, handle unauthorized route access, and dynamically update user permissions via middleware. While effective for Vue 2 projects, the broader Vue ecosystem has largely transitioned to Vue 3, making this package primarily relevant for maintaining existing Vue 2 applications, as its development and compatibility are centered around the older Vue version.
npm install vue-aclVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core setup of vue-acl, including installation, defining global rules, integrating with Vue Router for route protection, and passing the ACL instance to the root Vue instance. It also shows a basic `middleware` for dynamic permission changes and how to use `$acl.check()` within a component template.
For Vue 3 projects, consider alternatives like `vue-simple-acl` or `vacl`, or implement ACL logic natively using Vue 3's composition API.
Always append `.generate()` when creating a new `AclRule` instance: `new AclRule('permission').generate()`.Optimize API calls and data processing within the `middleware` to be as fast as possible. Consider caching results if appropriate.
Ensure `new Vue({ router, acl, ... })` includes your `acl` instance after calling `Vue.use(AclInstaller)` and instantiating `AclCreate`.Verify that `acl` is passed to the root Vue instance: `new Vue({ ..., acl, ... }).$mount('#app')`, and that `Vue.use(AclInstaller)` was called.For direct `AclRule` instances in `meta.rule`, ensure it's `new AclRule('permission').generate()`. For `globalRules`, ensure the string name matches exactly, e.g., `meta: { rule: 'isAdmin' }`.Check the `notfound` path and `forwardQueryParams` setting. Debug the `middleware` function to ensure `acl.change()` is called with the intended permission only after successful authentication or role determination.