Solution of Vue router loading components on demand

Now you can see the official website to explain how to load components on demand as follows:

// The combination of vue asynchronous components and webpack's [code chunking point] feature enables on-demand loading
const App = () => import('../component/Login.vue');

We usually report this error when using it:

Module build failed: SyntaxError: Unexpected token

It can be found that Import reported an error because Babel couldn’t resolve the error and needed to download the plug-in

cnpm install babel-plugin-syntax-dynamic-import --save-dev

Modify . Babelrc after downloading

{
  "presets": [
    ["env", { "modules": false }],
    "stage-3"
  ],
  "plugins": ["syntax-dynamic-import"]
}

In this way, it can be introduced on demand

Read More: