欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3?Error:Unknown?variable?dynamic?import:?../views/的解決方案

 更新時(shí)間:2023年07月10日 11:56:21   作者:桂亭亭  
這篇文章主要給大家介紹了關(guān)于vue3?Error:Unknown?variable?dynamic?import:?../views/的解決方案,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

報(bào)錯(cuò)截圖

錯(cuò)誤信息

vue-router.mjs:3451  Error: Unknown variable dynamic import: ../views/BlogGather/DetailsArticlePage/pc/DetailsArticlePage.vue
    at dynamic-import-helper:7:96
    at new Promise (<anonymous>)
    at default (dynamic-import-helper:6:12)
    at details.js?t=1681893616671:15:20
triggerError @ vue-router.mjs:3451
(匿名) @ vue-router.mjs:3173
Promise.catch(異步)
pushWithRedirect @ vue-router.mjs:3167
push @ vue-router.mjs:3099
fromDetail @ ArticleCard.vue:95
callWithErrorHandling @ runtime-core.esm-bundler.js:173
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:182
invoker @ runtime-dom.esm-bundler.js:345
dynamic-import-helper:7  Uncaught (in promise) Error: Unknown variable dynamic import: ../views/BlogGather/DetailsArticlePage/pc/DetailsArticlePage.vue
    at dynamic-import-helper:7:96
    at new Promise (<anonymous>)
    at default (dynamic-import-helper:6:12)
    at details.js?t=1681893616671:15:20

原來的代碼

const path = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) ? 'mobile/' : 'pc/'
console.log(path)
export const routes=[
    {
        name: "index",
        path: "/",
        component: ()=>import(`../views/BlogGather/IndexPage/${path}IndexPage.vue`),
        meta: {title: "博客"},
    },
    {
        name: "xq",
        path: "/DetailsArticlePage",
        component: import(`../views/BlogGather/DetailsArticlePage/${path}DetailsArticlePage.vue`),
        meta: {title: "詳情頁面"},
    },
];

這樣的寫法在Vue2中是可以正常運(yùn)行的但是在Vue3中就不可以了的。

修改后的代碼

const path = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) ? 'mobile/' : 'pc/'
console.log(path)
let modules = import.meta.glob('../views/BlogGather/**/**/*.vue')
console.log(modules)
export const routes=[
    {
        name: "index",
        path: "/",
        component: ()=>import(`../views/BlogGather/IndexPage/${path}IndexPage.vue`),
        meta: {title: "博客"},
    },
    {
        name: "xq",
        path: "/DetailsArticlePage",
        component: modules[(`../views/BlogGather/DetailsArticlePage/${path}DetailsArticlePage.vue`)],
        meta: {title: "詳情頁面"},
    },
];

我們注意到,我們是先將所有的vue文件讀取出來放到一個(gè)數(shù)組之中的。

然后再去數(shù)組中取值,這樣才能動(dòng)態(tài)的加載組件實(shí)現(xiàn)動(dòng)態(tài)路由的效果。

總結(jié)

到此這篇關(guān)于vue3 Error:Unknown variable dynamic import: ../views/的解決方案的文章就介紹到這了,更多相關(guān)Unknown variable dynamic import內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue基礎(chǔ)popover彈出框編寫及bug問題分析

    Vue基礎(chǔ)popover彈出框編寫及bug問題分析

    這篇文章主要為大家介紹了Vue基礎(chǔ)popover彈出框編寫及bug問題分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn)

    vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn)

    本文主要介紹了vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • vue打包時(shí)不刪除dist里的原有文件配置方法

    vue打包時(shí)不刪除dist里的原有文件配置方法

    這篇文章主要為大家介紹了vue打包時(shí)不刪除dist里的原有文件配置方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11
  • vue2中如何自定義組件的v-model

    vue2中如何自定義組件的v-model

    這篇文章主要介紹了vue2中如何自定義組件的v-model,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue實(shí)現(xiàn)隨機(jī)驗(yàn)證碼功能

    Vue實(shí)現(xiàn)隨機(jī)驗(yàn)證碼功能

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)隨機(jī)驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • 使用Vue-cli3.0創(chuàng)建的項(xiàng)目 如何發(fā)布npm包

    使用Vue-cli3.0創(chuàng)建的項(xiàng)目 如何發(fā)布npm包

    這篇文章主要介紹了使用Vue-cli3.0創(chuàng)建的項(xiàng)目,如何發(fā)布npm包,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-10-10
  • Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法(基于 vue + AntDesign)

    Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法(基于 vue + AntDesign)

    這篇文章主要介紹了Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法,該項(xiàng)目是基于 vue + AntDesign的,具體實(shí)例代碼給大家介紹的非常詳細(xì) ,需要的朋友可以參考下
    2019-11-11
  • Vue.js數(shù)字輸入框組件使用方法詳解

    Vue.js數(shù)字輸入框組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Vue.js數(shù)字輸入框組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • 淺析Vue2和Vue3中雙向綁定機(jī)制的優(yōu)化與差異

    淺析Vue2和Vue3中雙向綁定機(jī)制的優(yōu)化與差異

    Vue.js?核心特性之一就是雙向綁定,本文將深入探討?Vue2?和?Vue3?在雙向綁定上的區(qū)別,并分析這些改進(jìn)對(duì)性能和開發(fā)體驗(yàn)的影響,希望對(duì)大家有所幫助
    2024-11-11
  • 詳解Vue3.0 前的 TypeScript 最佳入門實(shí)踐

    詳解Vue3.0 前的 TypeScript 最佳入門實(shí)踐

    這篇文章主要介紹了詳解Vue3.0 前的 TypeScript 最佳入門實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06

最新評(píng)論