您是否正确注册了组件?

时间:2020-01-02 14:42:23

标签: vue.js

正如标题所述,我在Vue环境中遇到了麻烦。尽管我的问题与此处的其他主题具有相似之处,但我找不到适合我的具体情况的解决方案。

<template>
  <div id="background">
    <Header />
    <Buttons />
    <Viewer />
    <SmartME />
  </div>
</template>

<script>
import Header from './components/Header.vue';
import Buttons from './components/Buttons.vue';
import Viewer from './components/Viewer.vue';

const SmartME = require('../../sources/SmartME').default;

export default {
  name: 'App',
  components: {
    SmartME,
    Header,
    Buttons,
    Viewer,
  },
};
</script>

<style>
  #background {
    background: lightgreen;
    margin: -8px;
  }
</style>

这是错误控制台的日志:

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

found in

---> <App> at src/App.vue
       <Root>

编辑:

请随时向我询问有关此问题的更多详细信息(例如您可能认为有必要帮助我的屏幕截图和其他代码部分。

1 个答案:

答案 0 :(得分:1)

您的错误与使用require有关。为什么您不像上面的其他人那样使用import

import SmartME from '../../sources/SmartME';

import { default as SmartME } from '../../sources/SmartME';

取决于SmartME如何导出其模块