Vue.js 未知自定义元素,即使它在vue的组件部分中已清除

Vue.js 未知自定义元素,即使它在vue的组件部分中已清除,vue.js,Vue.js,在vue中,为什么我的comp没有渲染,而我得到了这个错误 Unknown custom element: <my-comp> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 这是因为功能性?如何解决此问题?您能否提供更多信息,说明为什么要使用功能属性? 你犯的错误肯定就是因为这个 尝试在main.js或app.

在vue中,为什么
我的comp
没有渲染,而我得到了这个错误

Unknown custom element: <my-comp> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

这是因为
功能性
?如何解决此问题?

您能否提供更多信息,说明为什么要使用
功能属性?
你犯的错误肯定就是因为这个

尝试在
main.js
app.js
文件中全局注册组件。像这样:
Vue.component('mycop',require('./components/mycop.Vue').default)

另一种不在全局注册组件的“丑陋”方法如下所示:

<template functional>
  <div>
    <component :is="props.components.MyComp"> <!-- works with <my-comp> tag as well -->
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
  props: {
    components: {
      type: Object,
      default() {
        return {
          MyComp
        };
      }
    }
  }
};
</script>
<template functional>
  <div>
    <component :is="injections.components.MyComp">
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
    inject: {
      components: {
        default: {
          MyComp
        }
      }
    }
  }
};
</script>

某物
从“/my comp.vue”导入MyComp;
导出默认值{
道具:{
组成部分:{
类型:对象,
默认值(){
返回{
麦康普
};
}
}
}
};
一个比上面更漂亮的代码方法是使用注入。它可能看起来像这样:

<template functional>
  <div>
    <component :is="props.components.MyComp"> <!-- works with <my-comp> tag as well -->
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
  props: {
    components: {
      type: Object,
      default() {
        return {
          MyComp
        };
      }
    }
  }
};
</script>
<template functional>
  <div>
    <component :is="injections.components.MyComp">
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
    inject: {
      components: {
        default: {
          MyComp
        }
      }
    }
  }
};
</script>

某物
从“/my comp.vue”导入MyComp;
导出默认值{
注入:{
组成部分:{
默认值:{
麦康普
}
}
}
}
};

您能否提供更多信息,说明为什么要使用
功能属性?
你犯的错误肯定就是因为这个

尝试在
main.js
app.js
文件中全局注册组件。像这样:
Vue.component('mycop',require('./components/mycop.Vue').default)

另一种不在全局注册组件的“丑陋”方法如下所示:

<template functional>
  <div>
    <component :is="props.components.MyComp"> <!-- works with <my-comp> tag as well -->
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
  props: {
    components: {
      type: Object,
      default() {
        return {
          MyComp
        };
      }
    }
  }
};
</script>
<template functional>
  <div>
    <component :is="injections.components.MyComp">
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
    inject: {
      components: {
        default: {
          MyComp
        }
      }
    }
  }
};
</script>

某物
从“/my comp.vue”导入MyComp;
导出默认值{
道具:{
组成部分:{
类型:对象,
默认值(){
返回{
麦康普
};
}
}
}
};
一个比上面更漂亮的代码方法是使用注入。它可能看起来像这样:

<template functional>
  <div>
    <component :is="props.components.MyComp"> <!-- works with <my-comp> tag as well -->
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
  props: {
    components: {
      type: Object,
      default() {
        return {
          MyComp
        };
      }
    }
  }
};
</script>
<template functional>
  <div>
    <component :is="injections.components.MyComp">
      <div>something</div>
    </component>
  </div>
</template>

<script lang="ts">
import MyComp from './my-comp.vue';

export default {
    inject: {
      components: {
        default: {
          MyComp
        }
      }
    }
  }
};
</script>

某物
从“/my comp.vue”导入MyComp;
导出默认值{
注入:{
组成部分:{
默认值:{
麦康普
}
}
}
}
};

因为我不需要在组件中使用脚本标记,我可以从模板访问
道具
。我已经更新了答案。也许这可能是你正在寻找的东西。但是如果我在父组件中使用v-for呢?它将多次注册组件。您是指父组件
foo.vue
?在该组件中,您可以从“/my comp.vue”中删除
import MyComp
组件:{'my comp':MyComp}
如果
MyComp
是全局注册的。或者我误解了你的说法?我不确定我想要全球的组件。我只在一个模块/页面中使用该组件,因为我不需要在组件中使用脚本标记,我可以从模板中访问
props
。我已经更新了答案。也许这可能是你正在寻找的东西。但是如果我在父组件中使用v-for呢?它将多次注册组件。您是指父组件
foo.vue
?在该组件中,您可以从“/my comp.vue”中删除
import MyComp
组件:{'my comp':MyComp}
如果
MyComp
是全局注册的。或者我误解了你的说法?我不确定我想要全球的组件。我只在一个模块/页面中使用该组件