Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

did you register the component correctly? For recursive components, make sure to provide the "name" option

Tags:

vue.js

I configured 'i-tab-pane': Tabpane but report error,the code is bellow:

<template>   <div class="page-common">     <i-tabs>       <i-tab-pane label="wx">         content       </i-tab-pane>     </i-tabs>   </div> </template>  <script>    import {     Tabs,     Tabpane   } from 'iview'    export default{     name:"data-center",     data(){       return {msg: 'hello vue'}     },     components: {       'i-tabs' : Tabs,       'i-tab-pane': Tabpane     }   } </script> 

Error traceback:

[Vue warn]: Unknown custom element: <i-tab-pane> - did you register the component correctly? For recursive components, make sure to provide the "name" option.  found in  ---> <DataCenter> at src/views/dc/data-center.vue        <Index> at src/views/index.vue          <App> at src/app.vue 

I have tried in the main.js to global configuration:

Vue.component("Tabpane", Tabpane); 

but still do not work. How to resolve this issue?

like image 749
user7693832 Avatar asked Mar 07 '18 14:03

user7693832


People also ask

Did you register the component correctly for recursive components make sure to?

To fix the 'did you register the component correctly? For recursive components, make sure to provide the "name" option' error in Vue. js, we should register the components we reference in our template. to register the i-tabs and i-tab-pane component where Tabs and TabPane are components.

What is a recursive component?

You could have just one Product Component that you could render on different pages as opposed to repeating the code for the Product Component on every page it's needed. A Vue component is considered recursive if it references itself within its own template.

How do I register a Vue component?

When we want to globally register a component in Vue, we need to do it in this file. All you have to do is import your component, as you usually would, and then register it using app. component . import { createApp } from 'vue' import App from './App.

What is Vue use?

Vue. js is a progressive framework for JavaScript used to build web interfaces and one-page applications. Not just for web interfaces, Vue. js is also used both for desktop and mobile app development with Electron framework.


1 Answers

If you're using a component within a component (e.g. something like this in the Vue DOM):

App   MyComponent    ADifferentComponent      MyComponent 

Here the issue is that MyComponent is both the parent and child of itself. This throws Vue into a loop, with each component depending on the other.

There's a few solutions to this:

 1. Globally register MyComponent

vue.component("MyComponent", MyComponent)

2. Using beforeCreate

beforeCreate: function () {   this.$options.components.MyComponent = require('./MyComponent.vue').default } 

3. Move the import into a lambda function within the components object

components: {   MyComponent: () => import('./MyComponent.vue') } 

My preference is the third option, it's the simplest tweak and fixes the issue in my case.


More info: Vue.js Official Docs — Handling Edge Cases: Circular References Between Components

Note: if you choose method's 2 or 3, in my instance I had to use this method in both the parent and child components to stop this issue arising.

like image 190
fredrivett Avatar answered Nov 03 '22 01:11

fredrivett