久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:5日期:2022-06-13 11:57:06
目錄報錯截圖錯誤信息原來的代碼修改后的代碼總結報錯截圖

錯誤信息

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:20triggerError @ vue-router.mjs:3451(匿名) @ vue-router.mjs:3173Promise.catch(異步)pushWithRedirect @ vue-router.mjs:3167push @ vue-router.mjs:3099fromDetail @ ArticleCard.vue:95callWithErrorHandling @ runtime-core.esm-bundler.js:173callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:182invoker @ runtime-dom.esm-bundler.js:345dynamic-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中是可以正常運行的但是在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文件讀取出來放到一個數組之中的。

然后再去數組中取值,這樣才能動態的加載組件實現動態路由的效果。

總結

到此這篇關于vue3 Error:Unknown variable dynamic import: ../views/的解決方案的文章就介紹到這了,更多相關Unknown variable dynamic import內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: JavaScript
主站蜘蛛池模板: 化德县| 盘锦市| 铜梁县| 九寨沟县| 涪陵区| 南乐县| 肇源县| 泗阳县| 启东市| 永平县| 内乡县| 宜章县| 鄂伦春自治旗| 邹城市| 准格尔旗| 岳阳县| 周至县| 黄石市| 通渭县| 伊吾县| 昭通市| 沂源县| 凤冈县| 咸阳市| 四平市| 宁城县| 娄烦县| 广宗县| 资源县| 册亨县| 达州市| 兴山县| 龙南县| 晋江市| 和林格尔县| 淮阳县| 隆化县| 大英县| 颍上县| 三原县| 涟水县|