最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to solve "Failed to resolve: component at App.vue" - Stack Overflow

programmeradmin2浏览0评论

I'm learning about ponents of Vue3 by referring to this video.

Around 6:37 in this video, header displayed on the test site when the tutor created Header.vue and edited App.vue. I wrote same code but get an error and nothing in displayed.

Any help would be appreciated.

Error message

[Vue warn]: Failed to resolve ponent: Header 
  at <App>
  runtime-core.esm-bundler.js?5c40:38

Code

[App.vue]

<template>
  <Header />
</template>

<script>
import Header from './ponents/Header.vue';

export default {
  setup() {
    return {
      Header
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Fira Sans', sans-serif;
}
body {
  background: #EEE;
}
</style>

[Header.vue]

<template>
  <h1>Ine Tracker</h1>
  <div class="total-ine">¥0</div>
</template>

<script>
export default {
    
}
</script>

<style scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background-color: #313131;
  border-bottom: 5px solid #FFCE00;
}
header h1 {
  color: #EEE;
  font-size: 28px;
}
header .total-ine {
  font-family: 'Fira Code', 'Fira Sans', sans-serif;
  background-color: #FFCE00;
  color: #FFF;
  font-size: 20px;
  font-weight: 900;
  padding: 5px 10px;
  min-width: 100px;
  text-align: center;
  border-radius: 8px;
  box-shadow: inset 0px 0px 6px rgba(0, 0, 0, 0.25);
  text-shadow: 0px 3px 3px rgba(0, 0, 0, 0.25);
}
</style>

I'm learning about ponents of Vue3 by referring to this video.

Around 6:37 in this video, header displayed on the test site when the tutor created Header.vue and edited App.vue. I wrote same code but get an error and nothing in displayed.

Any help would be appreciated.

Error message

[Vue warn]: Failed to resolve ponent: Header 
  at <App>
  runtime-core.esm-bundler.js?5c40:38

Code

[App.vue]

<template>
  <Header />
</template>

<script>
import Header from './ponents/Header.vue';

export default {
  setup() {
    return {
      Header
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Fira Sans', sans-serif;
}
body {
  background: #EEE;
}
</style>

[Header.vue]

<template>
  <h1>Ine Tracker</h1>
  <div class="total-ine">¥0</div>
</template>

<script>
export default {
    
}
</script>

<style scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background-color: #313131;
  border-bottom: 5px solid #FFCE00;
}
header h1 {
  color: #EEE;
  font-size: 28px;
}
header .total-ine {
  font-family: 'Fira Code', 'Fira Sans', sans-serif;
  background-color: #FFCE00;
  color: #FFF;
  font-size: 20px;
  font-weight: 900;
  padding: 5px 10px;
  min-width: 100px;
  text-align: center;
  border-radius: 8px;
  box-shadow: inset 0px 0px 6px rgba(0, 0, 0, 0.25);
  text-shadow: 0px 3px 3px rgba(0, 0, 0, 0.25);
}
</style>
Share Improve this question edited Jun 28, 2021 at 4:45 tony19 139k23 gold badges277 silver badges347 bronze badges asked Jun 28, 2021 at 4:26 TakicheeTakichee 1051 gold badge1 silver badge9 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

The Header ponent is not properly registered in App.vue. I believe you were trying local ponent registration from setup(), but that's currently not supported.

Use the ponents option to locally register Header in App.vue:

import Header from './ponents/Header.vue';

export default {
  ponents: {
    Header
  },

  setup() {
    // DON'T DO THIS
    //return {
    //  Header
    //}
  }
}

demo

You need to wrap child elements inside the single parent element of Header ponent.

<template>
  <div>
      <h1>Ine Tracker</h1>
      <div class="total-ine">¥0</div>
   </div>
</template>

You need to include your header ponent in the App.vue, try this

<template>
  <Header />
</template>

<script>
import Header from './ponents/Header.vue';

export default {
    ponents: {
            Header,
    },

}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Fira Sans', sans-serif;
}
body {
  background: #EEE;
}
</style>
发布评论

评论列表(0)

  1. 暂无评论