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

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

javascript - vue使用異步組件結合is按需加載組件的問題

瀏覽:113日期:2023-05-24 08:57:32

問題描述

<el-tabs v-model='activeName' @tab-click='handleClick' type='border-card'> <el-tab-pane v-for='item in menu' :label='item.name' :name='item.name' :key='item' :component='item.component'><component :is='item.component'></component></el-tab-pane> </el-tabs>

methods: { handleClick (tab, event) {// 異步加載組件let getCompoentIndex = this.menu.findIndex(x => x.name === tab.name)let component = this.menu[getCompoentIndex].componentif (!this.menu[getCompoentIndex].loading) { this.menu[getCompoentIndex].loading = true Vue.component(component, function (resolve, reject) { setTimeout(function () { require([`./${component}.vue`], resolve)//比如 abc.vue }, 1000) })} } }

點擊的時候去加載異步組件(可以載入組件),但報下面的錯

[Vue warn]: Unknown custom element: <abc> - did you register the component correctly? For recursive components, make sure to provide the 'name' option.

嘗試為abc組件加上name還是報這樣的錯,有人知道怎么解決嗎?abc.vue

export default { name: ’abc’,}

問題解答

回答1:

找出了方法就是加上if判斷

<el-tab-pane v-for='item in menu' :label='item.name' :name='item.name' :key='item' :component='item.component'><component :is='item.component' v-if=’flag’></component></el-tab-pane>

data:()=>({ flag: false})

然后在點擊的時候把flag設置為true就解決了那個報錯問題

回答2:

我是用WEBPACK解決的。可以參看我的項目。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 托里县| 剑川县| 田林县| 明水县| 屯门区| 磐安县| 满洲里市| 固原市| 关岭| 秀山| 德钦县| 庆元县| 镇江市| 平陆县| 卢龙县| 柳州市| 吉安市| 葵青区| 寿阳县| 射洪县| 肥西县| 旺苍县| 保亭| 高阳县| 珠海市| 霍城县| 鄂州市| 白河县| 北宁市| 镇巴县| 巴彦淖尔市| 岐山县| 科技| 樟树市| 邳州市| 河南省| 宁城县| 正镶白旗| 抚顺市| 鸡泽县| 黄陵县|