[英]vue2 component not showing up
It's my first Vue2 project, and I'm trying to create a component called Menu
which will be used in the app's main page. 这是我的第一个Vue2项目,我正在尝试创建一个名为
Menu
的组件,该组件将在应用程序的主页中使用。
I created the project using vue-cli
and my dependency manager is yarn
. 我使用
vue-cli
创建了该项目,而我的依赖项管理器是yarn
。 I run the project by yarn run dev
. 我通过
yarn run dev
运行该项目。
This is my project structure: 这是我的项目结构:
myproject
- src
- components
- Menu.vue
- App.vue
- main.js
Menu.vue: Menu.vue:
<template>
<ul class="nav">
<li class="active">
<a href="dashboard.html">
<i class="ti-panel"></i>
<p>Dashboard</p>
</a>
</li>
</ul>
</template>
<script>
export default {
name: 'Menu'
}
</script>
App.vue: App.vue:
<template>
<div id="app" class="wrapper">
<div class="sidebar" data-background-color="white" data-active-color="danger">
<div class="sidebar-wrapper">
<div class="logo">
<a href="#" class="simple-text">
LOGO
</a>
</div>
<menu></menu>
</div>
</div>
</div>
</template>
<script>
import Menu from './components/Menu'
export default {
name: 'App',
components: {
'menu': Menu
}
}
</script>
main.js: main.js:
import Vue from 'vue'
import App from './App'
import Menu from './components/Menu'
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App, Menu },
template: '<App/>'
})
When running yarn run dev
no error is shown in the console, however the webpage shows a link with text "LOGO" and an empty <menu>
element, while I was expecting vue to replace that tag with the <template>
from Menu.vue
. 当运行
yarn run dev
时,控制台中未显示任何错误,但是网页显示了带有文本“ LOGO”和空的<menu>
元素的链接,而我希望vue用Menu.vue
的<template>
替换该标签。 。
Why isn't it working? 为什么不起作用? What am I missing?
我想念什么?
You should be getting this error (not sure why you aren't seeing it): 您应该会收到此错误(不确定为什么看不到它):
[Vue warn]: Do not use built-in or reserved HTML elements as component id: menu
[警告]:请勿将内置或保留的HTML元素用作组件ID:菜单
The fix would be to change the component name to something that isn't a reserved HTML element: 解决方法是将组件名称更改为非保留HTML元素:
<script>
import MyMenu from './components/MyMenu'
export default {
name: 'App',
components: {
'my-menu': MyMenu
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.