我正在尝试创建可在多个视图中使用的图块组件。我已经在视图中调用了该组件,但是它不起作用
组件代码(Tile.vue)
<template>
<div class="tile">
<label class="title">Tile Title</label>
</div>
</template>
<script>
export default {
name: 'CustomTile'
}
</script>
<style scoped lang="less">
.tile { width:248px;
height: 126px;
background-color:#e4e4e4;
.title {
padding-left: 15px;
}
}
</style>
我试图在上面的组件中调用的视图代码(Report.vue)
<template>
<div>
<div class="topnav">
<button type="button">Expand/Collapse</button>
</div>
<div class="content">
<CustomTile></CustomTile>
</div>
</div>
</template>
<script>
import CustomTile from '@/components/Tile.vue'
export default {
name: 'Report'
}
</script>
<style scoped lang="less">
.topnav {
overflow: hidden;
background-color: #d6d6d6;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}.topnav a.active {
background-color: #4CAF50;
color: white;
}
.content {
height:500px;
width:500px;
}
</style>
CustomTile未呈现。我无法弄清楚问题出在哪里。
答案 0 :(得分:1)
您需要在要使用它的父级中正确导入该组件并进行注册:
Report.vue:
<script>
import CustomTile from '@/components/Tile.vue'
export default {
name: 'Report',
components: {
CustomTile
}
}
</script>
然后,由于CustomTile
是CamelCase组件名称,因此您需要使用以下表示法:
<custom-tile></custom-tile>