The implementation scheme of vue: generating route (dynamic route) according to the value from the background

the company wants to do a background management system, and then different roles may correspond to different left menus, that is, a dynamic route, and everyone can see different things.
I have seen the document of "Flower underpants" before, that is, the backend returns the user role, and then the front end dynamically controls the route according to the user role. Now I want the backend to return the data directly, and then render the data according to the data
the backend returns similar data:

clipboard.png
and then use the addRoutes method to implement
. I would like to ask if you have ever done this, and whether it is reasonable to do so, or do you have any plans that have been practiced. I hope you can put forward some suggestions

.

the train of thought has been stated in the previous few floors, basically, it is to write the route normally first, and then judge whether to show it to the user or not according to the permission. Let me add a practical one.

  1. encapsulate the left column into a component, such as nav:

clipboard.png

2.props
clipboard.png


vue

1.router.beforeEach,
2.concatrouter.addRoutes
3.routes


""


vue-routeradd
demomock


1json;
2;
3 ;
4;
5index.vue ;


:
:tree
:tree
:
:



background control should be good, flexible, data-driven


can be changed direction, that is, admin has the highest permissions, with all permissions, you can see all the sidebar navigation, that is, there are all routes in the page, and other permissions can be matched through the data passed from the backstage, and the sidebar navigation can be displayed and hidden accordingly. Vue has not been used much. Like adding v-if=false to the navigation label, it is more appropriate to add the route control in vue to control the url of the current route. Simply hide the navigation


the solution on the same floor
I also apply it in the project. The trouble only lies in the match negotiated between you and the backend
the logical idea on my side is to hide all the data first, display the corresponding routes after obtaining the data, and then verify the permissions of the route.to targets through the navigation guards. I wrote a vue plug-in to inject my permission verification method into the vue instance to do a more detailed button-level front-end permission check.
the two solutions are actually similar. The former may be more troublesome for local developers, and it is difficult to work when there is no interface.
both methods have unified disadvantages and cannot make corresponding changes to the permissions of currently logged-in users in real time.
in the final analysis, the front end is only to assist in verifying permissions to optimize customer experience. After all, only the back-end permission verification is valid


encapsulate the left menu into a component and then control the display of the menu through the background data.


two scenarios.
Scheme 1, route all permissions are registered, and the display navigation id, is dynamically obtained. In order to prevent users from entering the address bar directly, a route interceptor is added.

Plan 2: register routes strictly according to permissions. Before vue instantiation, obtain registrable routes asynchronously, and then register

.

is actually the part of rights management. Different users may have different menus and different items are displayed in the menu bar on the left. The left encapsulates the component, and the data is processed through the back end to return different menu items.


ask the value of component, and how to send it to the background


there are such requirements in general background management systems
1, roles can be configured, each role has different menu permissions, data is stored in the database
2, roles are assigned to users when users are created
3, menu permissions are returned in the background when users log in pages (read)
4, and the front end renders menus according to permission data

premise that, as mentioned by several people upstairs, the front end also needs to have a complete route map

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdc3b0-312cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdc3b0-312cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?