日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【Vue】 Error with Vue lazy loading components: “Failed to resolve async component“

發布時間:2025/3/20 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Vue】 Error with Vue lazy loading components: “Failed to resolve async component“ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 可能出現問題的情況
    • 情況一:路徑問題
    • 情況二:每個組件的name 值
    • 情況三:駝峰命名法問題
      • 方式一:
      • 方式二:
    • 情況四:vue1.0和2.0的寫法不同
    • 情況五:組件中含有 style 標簽
    • 情況六:省略了index.vue
    • 情況七:使用 webpackChunkName
    • 情況八:routes/index.js中,函數調用
      • 錯誤情況
      • 正確情況
  • 排錯方式
    • 安裝vue-tools
    • 使用未壓縮的vue.js
  • 參考鏈接:

可能出現問題的情況

情況一:路徑問題

引入路徑不能使用 加號進行字符串與變量的拼接,應使用 ``

# 錯誤示例: function view(name) {return () => import('../pages/'+name) }# 正確示例: function view(name) {return () => import(`../pages/${name}`) }

情況二:每個組件的name 值

參考鏈接:https://blog.csdn.net/weixin_41790566/article/details/107520109

情況三:駝峰命名法問題

見vue官網:https://vuejs.org/v2/guide/components-registration.html#Name-Casing

方式一:

聲明:MyChild
使用:<my-child></my-child> 或 <MyChild>

方式二:

聲明:mychild
使用:<mychild>

情況四:vue1.0和2.0的寫法不同

1.0中

new Vue({el: '#app',components: { App } });

2.0應該加一行

new Vue({el: '#app',template: '<App/>',components: { App } });

情況五:組件中含有 style 標簽

解決:刪除 style

情況六:省略了index.vue

錯誤示例: let userIdx = () => import('./views/user');正確示例: let userIdx = () => import('./views/user/index.vue');

情況七:使用 webpackChunkName

## 添加 webpackChunkNamecomponents: {maingraph: ()=>import(/* webpackChunkName: "maingraph" */ "../components/echartself/maingraph"),},

情況八:routes/index.js中,函數調用

錯誤情況

const view = function (name) {return () => import(`../pages/${name}`) } const routes = [{path: '/home',name: 'app-home',component: view('home.vue'),}},

正確情況

const view = function (name) {return () => import(`../pages/${name}.vue`) # 此處更改 } const routes = [{path: '/home',name: 'app-home',component: view('home'), # 此處更改}},

排錯方式

安裝vue-tools

https://github.com/vuejs/vue-devtools

使用未壓縮的vue.js

參考鏈接:

https://github.com/JeffreyWay/laravel-mix/issues/2064

總結

以上是生活随笔為你收集整理的【Vue】 Error with Vue lazy loading components: “Failed to resolve async component“的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。