【问题标题】:[Vue warn]: Failed to resolve component: Step1Item:[Vue 警告]:无法解析组件:Step1Item:
【发布时间】:2021-02-26 08:56:18
【问题描述】:

当我尝试在组件中的组件上使用 v-for 指令时,出现上述错误。

这正在工作并迭代存储在参与者中的一些数据

<template>
    <div
        v-for="(participant, index) in participants"
        v-bind:key="index"
        >
        hello world
    </div>
</template>

但是改成这个会给我上面的错误。

<template>
    <Step1Item
        v-for="(participant, index) in participants"
        v-bind:key="index"
        >
        hello world
    </Step1Item>
</template>

<script>
    import Step1Item from "./Step1Item.vue";

    export default {
        name: "Step1",
        components: Step1Item,
    [...] 
</script>

组件是:

<template>
    <div>
        {{ name }}
    </div>
</template>

<script>
export default {
    name: "Step1Item",
    props: {
        name: String,
    },
};
</script>

【问题讨论】:

标签: vue.js vue-component


【解决方案1】:

你写的components选项不正确,应该是:

 components: {Step1Item},

components 选项具有作为 componentName:component 对的对象的值,但您可以使用简写语法 components: {component1,component2,...}, 编写它

【讨论】:

  • 非常感谢。我只是浪费了 2 个多小时,因为我将组件添加为数组而不是对象。
猜你喜欢
  • 2021-11-13
  • 2021-01-03
  • 2015-06-14
  • 2021-09-21
  • 2021-06-11
  • 1970-01-01
  • 2021-11-02
  • 2017-05-28
  • 2017-12-06
相关资源
最近更新 更多