簡體   English   中英

Vue路由器無法延遲加載子組件

[英]Vue-router cannot lazy load child component

我在項目內使用vue-router,不幸的是,該庫正在與不在活動開發中的庫一起使用。 我需要在其中添加一些內容,因此我下載了源代碼,自己對其進行了編輯,然后將其構建到項目的“外部”文件夾中。

現在,直到該項目不使用前端路由器,一切都可以正常工作,但是最近,我用延遲加載組件實現了vue-router,事情變得有些棘手。

我剛才說的庫保存在@/externals/date-picker 在我的延遲加載組件內部,我使用es6 import導入它:

import DatePicker from '@/externals/date-picker';

觸發vue-router內部錯誤:

無法解析異步組件默認值:TypeError:無法設置未定義的屬性“ vue-date-picker”

我不知道發生了什么,但是似乎無法將date- module.exports添加到module.exports

我很確定即使是延遲加載的外部文件也必須有一種加載方法。 因此,我的問題是,如何將外部文件/程序包添加到延遲加載的組件中? 先感謝您。

// router.js
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);

export default new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/something',
            name: 'something',
            title: 'something',
            component: () => import(/* webpackChunkName: "something" */ './views/Component.vue')
        }
    ]
});

// Component.vue
<script>
    import DatePickerOriginal from "@/external/date-picker";

    export default {
        components: {
            DatePickerOriginal
        }
    };
</script>

@/external/date-picker的源代碼與此處幾乎相同(嗯,構建工具是相同的,並且應用程序本身很可能不會引起問題)。 另外,再次指出,應用程序不在其他軟件包的node_modules文件夾中,而是從@/externals/date-picker node_modules加載的。

看起來像我在Webpack配置中缺少libraryTarget: 'window'時,在構建過程中合並包。

merge(commonConfig, {
    entry: path.resolve(__dirname + '/src/plugin.js'),
    output: {
        // ...
        libraryTarget: 'window'
    }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM