Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack Web包vue路由器延迟加载_Webpack_Vue.js_Lazy Loading_Vue Router - Fatal编程技术网

Webpack Web包vue路由器延迟加载

Webpack Web包vue路由器延迟加载,webpack,vue.js,lazy-loading,vue-router,Webpack,Vue.js,Lazy Loading,Vue Router,从vue路由器 要延迟加载组件,我正在使用语法: const Foo = () => import('./Foo.vue') 我有一个错误: client?cd17:49 ./src/routes.js Module build failed: SyntaxError: Unexpected token (5:19) 3 | 4 | //const User = () => System.import('./components/user/User.vue');

从vue路由器 要延迟加载组件,我正在使用语法:

const Foo = () => import('./Foo.vue')
我有一个错误:

    client?cd17:49 ./src/routes.js
Module build failed: SyntaxError: Unexpected token (5:19)

  3 | 
  4 | //const User = () => System.import('./components/user/User.vue');
> 5 | const User = () => import('./components/user/User.vue')
    |                    ^
  6 | const UserStart = () => System.import('./components/user/UserStart.vue');
  7 | const UserDetail = () => System.import('./components/user/UserDetail.vue');
  8 | const UserEdit = () => System.import('./components/user/UserEdit.vue');

BabelLoaderError: SyntaxError: Unexpected token (5:19)

  3 | 
  4 | //const User = () => System.import('./components/user/User.vue');
> 5 | const User = () => import('./components/user/User.vue')
    |                    ^
  6 | const UserStart = () => System.import('./components/user/UserStart.vue');
  7 | const UserDetail = () => System.import('./components/user/UserDetail.vue');
  8 | const UserEdit = () => System.import('./components/user/UserEdit.vue');

    at transpile (/app/node_modules/babel-loader/lib/index.js:61:13)
    at Object.module.exports (/app/node_modules/babel-loader/lib/index.js:163:20)
 @ ./src/main.js 4:0-34
 @ multi main
errors @ client?cd17:49
sock.onmessage @ client?cd17:83
EventTarget.dispatchEvent @ eventtarget.js?3e89:51
(anonymous) @ main.js?45b8:274
SockJS._transportMessage @ main.js?45b8:272
EventEmitter.emit @ emitter.js?927b:50
WebSocketTransport.ws.onmessage @ websocket.js?c17e:35
之后我安装了

npm install --save-dev babel-preset-stage-2

还将.lrc文件配置为:

{
  "presets": [
    ["es2015", { "modules": false }],
    "stage-2"
  ],
  "plugins": [
    "transform-export-extensions"
  ]
}

没有任何帮助,我如何使用此
const Foo=()=>import('./Foo.vue')
语法使用webpack和vue路由器惰性地加载组件?

安装所需的babel插件:

npm install --save-dev babel-plugin-syntax-dynamic-import
在项目根目录中创建.babelrc,在文件中包含以下短代码:

{
    "plugins": ["syntax-dynamic-import"]
}
使用这种方式导入后:

常量Foo=()=>import('./Foo.vue')


最终运行npm build(vue cli)或npm run watch(laravel)

安装所需的babel插件:

npm install --save-dev babel-plugin-syntax-dynamic-import
在项目根目录中创建.babelrc,在文件中包含以下短代码:

{
    "plugins": ["syntax-dynamic-import"]
}
使用这种方式导入后:

常量Foo=()=>import('./Foo.vue')


最终运行npm build(vue cli)或npm run watch(laravel)

您正在以异步方式运行,因此特定方法不能仅在分配时导入组件。这可能会对您有所帮助-您使用的是什么版本的webpack?您使用的是异步方式,所以特定的方法不能仅在分配时导入组件。这可能会帮助你-你使用什么版本的网页包?