【发布时间】:2021-11-27 05:07:52
【问题描述】:
您好,刚接触 Vue 并通过教程学习。我创建了一个组件 Header.vue 并尝试将其导入 App.vue。 这是结构: code structure
这里是 App.vue:
<template>
<Header />
</template>
<script>
import Header from "./components/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>
<div>
<h1>Income Tracker</h1>
<div class="total-income">$0</div>
</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-income {
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>
我从 App.vue 获取样式,但组件没有解析。在控制台中,我收到此错误: error message
我尝试的是堆栈溢出和基于错误消息文本的谷歌搜索。
要么我没有正确搜索,要么我目前没有足够的经验来确定导致此问题的问题。
非常感谢您提供有关如何解决此问题的教育。
【问题讨论】:
-
我建议不要使用
Header作为组件名称,因为它可能与 HTMLheaderelement 冲突。这违反了very first rule in the Vue Style Guide。 -
我认为本教程是一个小怪人.. 已经学到了更多在这里解决问题的前 4 分钟。
标签: javascript vue.js components