Vue-Router не поддерживает функцию динамического импорта () - PullRequest
0 голосов
/ 01 июля 2019

Код ниже выдает unexpected token import

const Router = new VueRouter({
    routes: [
      { path: '', component: () => import('pages/landing/landing') }
    ]
})

Это работает, если я делаю, как показано ниже:

import landing from 'pages/landing/landing';
const LandingComp = Vue.component('search-product', landing);

const Router = new VueRouter({
    routes: [
        { path: '', component: LandingComp }
    ]
})

Но я не хочу загружать все компоненты изначально. Я хотел загружать динамически, когда это требуется.

Любая помощь будет оценена. Спасибо!

Ответы [ 2 ]

0 голосов
/ 01 июля 2019
import LandingComp = () => { 
    import landing from 'pages/landing/landing'
    Vue.component('search-product', landing)
}

const Router = new VueRouter({
    routes: [
        { path: '', component: LandingComp }
    ]
})

вы можете попробовать

0 голосов
/ 01 июля 2019

Динамический импорт включается при правильной конфигурации Babel. Вы должны правильно настроить Babel. Смотрите здесь .

...