vue.js - VueJS 未知自定义元素在单个文件组件中具有嵌套模板

标签 vue.js vue-component vuejs2

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

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

我也在使用单文件组件。 对于 <app>组件看起来像这样(/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>

<column>组件(/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>

<task>组件(/components/Task.vue 文件):

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

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

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

      }
    }
  }
</script>

到目前为止,一切都完美无缺。该应用程序呈现一堆列,并在列内呈现任务。 但接下来是另一层 <resource> ,看起来像这样(/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>

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

最佳答案

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

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

应该是这样的:

import resources from './Init-resource'

关于vue.js - VueJS 未知自定义元素在单个文件组件中具有嵌套模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120467/

相关文章:

html - 将 json 对象一个组件传递给另一个 vuejs

javascript - Chrome/Safari 在不同时间触发点击事件

javascript - 如何访问Vue中所有组件中的对象内部的数据

javascript - vuejs中多维数组应该怎么取?

html - 如何 v-model 2 值?

vue.js - 使用 vue.js 和 vuetify 进行服务器端表单验证

vue.js - 关闭 Nuxt 应用程序中的 webpack-hot-middleware 客户端覆盖

vue.js - 如何用 jest 在单元测试中测试 bootstrap vue 组件的存在?

typescript - 使用 this.$parent.somePropOrMethod 和 this.$root.somePropOrMethod 时,属性 X 在类型 'Vue' 上不存在

javascript - 如何在 Vuex/Nuxt 中设置值