Dynamic introduction of components in vue routing (various ways of writing import and require)

Dynamic introduction of components in vue routing (various ways of writing import and require)

Commonly used import writing method (as shown in the figure below):
insert image description here
Commonly used to write and send, first use import to import component objects through the path, and then assign them to the component.

slightly more advanced

insert image description here
Directly "@" to the target main folder, no need to type so many dots.

The combination of the first and the second can achieve lazy loading.

insert image description here
Source conversion:

const login = () => import('@/views/login/index')
...
{
...
    component: login,
  ...
  },

When there are many routes in the project, it may be necessary to dynamically set the route according to the array. In the setting, the method of dynamically setting the import address of the component component object:

let url = 'xxxxxxx'
{
...
component: () =>

Guess you like

Origin blog.csdn.net/start_sea/article/details/129756516
Recommended