无法在 vue cli 应用程序中调用 Vue 组件
Not able to call Vue component in vue cli application
我正在尝试创建可在多个视图中使用的图块组件。我已经调用了视图中的组件,但它不工作
组件代码 (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 未呈现。我无法弄清楚 what/where 是问题所在。
您需要在您要使用它的父组件中正确导入组件并注册它:
Report.vue:
<script>
import CustomTile from '@/components/Tile.vue'
export default {
name: 'Report',
components: {
CustomTile
}
}
</script>
然后,由于CustomTile
是一个CamelCase组件名称,您需要使用以下表示法:
<custom-tile></custom-tile>
我正在尝试创建可在多个视图中使用的图块组件。我已经调用了视图中的组件,但它不工作
组件代码 (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 未呈现。我无法弄清楚 what/where 是问题所在。
您需要在您要使用它的父组件中正确导入组件并注册它:
Report.vue:
<script>
import CustomTile from '@/components/Tile.vue'
export default {
name: 'Report',
components: {
CustomTile
}
}
</script>
然后,由于CustomTile
是一个CamelCase组件名称,您需要使用以下表示法:
<custom-tile></custom-tile>