【问题标题】:VueJS Unknown custom element with nested template in single file componentsVueJS 未知自定义元素在单个文件组件中具有嵌套模板
【发布时间】:2017-04-28 11:26:30
【问题描述】:

我有一个带有 vue 的嵌套结构:

<app>
  <column> : [array]
    <task> : [array]
      <resource> : [array]

我也在使用单个文件组件。 对于&lt;app&gt; 组件,它看起来像这样(/App.vue 文件)

<template>
  <div id="app">
     <column v-for=""></column>
  </div>
</template>

<script>
  import column from './components/Column'

  export default {
    name: 'project',
    components: {
      column
    },  
    data () {
      return {

      }
    }
  }
</script>

&lt;column&gt; 组件(/components/Column.vue 文件):

<template>
  <div>
      <task v-for=""></task>
  </div>
</template>

<script>
  import task from './Task'

  export default {
    name: 'column',
    components: {
      task
    },
    data () {
      return {

      }
    }
  }
</script>

&lt;task&gt; 组件(/components/Task.vue 文件):

<template>
  <div>
      <resources></resources>
  </div>
</template>

<script>
  import { resources } from './Init-resource'

  export default {
    name: 'task',
    components: {
      resources
    },
    data () {
      return {

      }
    }
  }
</script>

到目前为止,一切都完美无缺。该应用程序呈现一堆列,并在列内呈现任务。 但接下来是另一层&lt;resource&gt;,看起来像这样(/components/Init-resource.vue 文件):

<template>
  <div>
    <select>
      <option v-for=""></option>
    </select>
  </div>
</template>

<script>
  export default {
    name: 'resources',
    data () {
      return {

      }
    }
  }
</script>

我收到此错误:

vue.common.js?e881:509 [Vue warn]: Unknown custom element: <resources> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 
(found in component <task>

它无法识别最后一个 &lt;resource&gt; 组件。但是一切看起来都很好,导入是正确的,为模板返回了组件......

【问题讨论】:

    标签: vue.js vue-component vuejs2


    【解决方案1】:

    我找到了。我使用了命名导入,所以不是这个:

    import { resources } from './Init-resource'
    

    应该是这样的:

    import resources from './Init-resource'
    

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 2020-12-03
      • 2020-01-01
      • 2017-08-10
      • 2018-08-12
      • 2018-05-29
      • 2021-11-24
      • 2018-05-06
      • 1970-01-01
      相关资源
      最近更新 更多