問題由來
最近在做項目的時候遇到使用循環組件,因為模式一樣,只有數據不一樣。按照普通組件調用格式來做的時候總是報錯,錯誤信息為[Vue warn]: Unknown custom element: <selfile> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
解決方案
查詢了網上各種資料之后,發現是循環調用組件時,組件比vue實例后創建,官方文檔里寫組件必須先于實例化引入,所以說組件沒有正確的引入。
解決方式
解決的方式就是全局引入組件,并且在vue實例化前。
具體到我們項目中,就是在main.js里引入。
具體代碼如下main.js:
import Vue from 'vue'import App from './App'import router from './router'import store from './store';import iView from 'iview';import './styles/index.less'import {VTable,VPagination} from 'vue-easytable'import 'vue-easytable/libs/themes-base/index.css'import Axios from './utils/axiosPlugin'import './styles/button.css'import './styles/common.css'// require('./mock/mock')import selFile from './views/file/selFile.vue'Vue.use(iView);Vue.use(Axios);Vue.component(VTable.name, VTable)Vue.component(VPagination.name, VPagination)Vue.component("selFile",selFile)Vue.config.productionTip = false/* eslint-disable no-new */new Vue({ el: '#app', store, router, components: { App }, template: '<App/>'})用上面的方法全局引入組件就可以解決循環引用組件報錯的問題。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選