vue3+vite打包当前,我的项目切换路由触发(偶发触发)报:
After using vue-router, there is an error in packaging and running # Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Failed to fetch dynamically imported module.....
的确应该是vite2.xx的bug https://github.com/vitejs/vite/issues/863
留神: 在应用vue3+vite时候,只发现vue-router切换时触发此景象
问题:
// vue3+vite此种异步路由引入办法 开发调试时的确没有问题,然而vite打包当前就会触发报错routes: [ { path: "/", name: "Home", component: import(`../views/${view}.vue`) }]
解决办法:
// 这样援用尽管解决了问题(浏览器会揭示,不必管),然而在一些win10自带的低版本edge浏览器中还是会罕见触发// 应该的确是vite的兼容性bug问题import { defineAsyncComponent } from 'vue'; //异步组挂载器routes: [ { path: "/", name: "Home", component: defineAsyncComponent(() => import('../views/Home.vue')); }, { path: "/about", name: "About", component: defineAsyncComponent(() => import('../views/About.vue')); }]
后续继续跟进中...