javascript - Vue 3 - "Failed to resolve component"

我有这个 SocialNetworks.vue 组件

<template>
  <div class="socialNetworks">
    <SocialLink to="https://twitter.com/" icon="twitter.svg" name="twitter" />
    <SocialLink
      to="https://facebook.com/"
      icon="facebook.svg"
      name="facebook"
    />
    <SocialLink to="https://github.com/" icon="github.svg" name="github" />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { SocialLink } from '@/components/atoms'
export default defineComponent({
  component: { SocialLink }
})
</script>

<style lang="scss" scoped>
.socialNetworks {
  display: grid;
  grid-gap: 1rem;
}
</style>

使用这个子 SocialLink.vue 组件

<template>
  <a class="socialLink" :href="to">
    <img src="@/assets/images/icons/search.svg" :alt="name" />
  </a>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  props: {
    name: { Type: String, required: true },
    icon: { Type: String, required: true },
    to: { Type: String, required: true }
  },
  computed: {
    iconPath(): string {
      return require(`@/assets/images/icons/${this.icon}`)
    }
  }
})
</script>

<style lang="scss" scoped>
.socialLink {
  background-color: #ff895f;
  width: 47px;
  height: 47px;
  border-radius: 5rem;
  display: grid;
  justify-items: center;
  align-items: center;
  transition: transform 0.2s linear;
  &:hover {
    transform: scale(1.1);
  }
  img {
    width: 23px;
    height: 23px;
  }
}
</style>

我在此 SitePresentation.vue 中使用了 SocialNetworks.vue 组件

<template>
  <a class="socialLink" :href="to">
    <img src="@/assets/images/icons/search.svg" :alt="name" />
  </a>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  props: {
    name: { Type: String, required: true },
    icon: { Type: String, required: true },
    to: { Type: String, required: true }
  },
  computed: {
    iconPath(): string {
      return require(`@/assets/images/icons/${this.icon}`)
    }
  }
})
</script>

<style lang="scss" scoped>
.socialLink {
  background-color: #ff895f;
  width: 47px;
  height: 47px;
  border-radius: 5rem;
  display: grid;
  justify-items: center;
  align-items: center;
  transition: transform 0.2s linear;
  &:hover {
    transform: scale(1.1);
  }
  img {
    width: 23px;
    height: 23px;
  }
}
</style>

我觉得一切都很好,但我一直在我的控制台中收到这个

[Vue warn]: Failed to resolve component: SocialLink
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
  at <SocialNetworks> 
  at <SitePresentation> 
  at <SiteContainer class="homeTemplate" > 
  at <HomeTemplate> 
  at <App>

SitePresentation.vue 中的图像工作得很好,svg 没问题,导入的路径据我所知是正确的。我试着不调用 require,而是调用其中一个硬编码的 svg,就像我在演示组件中所做的那样。我认为问题可能出在 SocialLink.vue 组件中,但我不太确定到底是什么问题 我的代码中有什么奇怪的地方,或者我忽略了一些细节?

最佳答案

您的 component 属性应该是 components!

export default defineComponent({
  components: { SocialLink }
})

https://vuejs.org/api/options-misc.html#components

关于javascript - Vue 3 - "Failed to resolve component"带有子组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71879314/

相关文章:

c++ - 检查是否存在嵌套类型别名并有条件地设置类型别名

reactjs - antd DatePicker 或 RangePicker 如何让日历图标左对齐

haskell - 为什么类型为 [tail, init, reverse], [[a] -> [a

c# - 无法启动程序,访问被拒绝 C# net6.0

r - 将嵌套列表中的名称分配给它的子组件

javascript - 解决对多个参数值的 promise

python - 正确完成所有操作后出现 Ngrok 错误 6022

javascript - Nuxt中如何使用动态图片?

go - 用类型参数替换接口(interface)参数有什么好处?

html - 一个 SVG 的多个路径的多个复选框