我可以在根 App.vue 组件中嵌套组件,但如果我尝试将组件嵌套在非根组件中,则不会显示任何内容。如果我将不会在 Splash.vue 中显示的导航栏组件嵌套在 App.vue 中,则它可以工作,同样,如果我将页脚组件移动到 Splash.vue,它也不会。
App.vue(页脚组件工作正常,路由器然后加载splash.vue)
<template>
<div id="app">
<Footer/>
<router-view/>
</div>
</template>
<script>
import Footer from '@/components/Footer'
export default {
name: 'App',
components: {
Footer
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 0px;
}
</style>
Splash.vue(导航栏组件未加载,文本已加载,因此我知道路由器工作正常)
<template>
<div class="test">
<v-container fluid>
<Navbar/>
<p>splash loaded</p>
</v-container>
</div>
</template>
<script>
import Navbar from '@/components/layout/Navbar'
export default {
name: 'Splash',
data () {
return {
components: {
Navbar
}
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.landing-card-style {
border-radius: 4px;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.14);
}
</style>
main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
Vue.use(Vuetify)
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
render: h => h(App)
})
Navbar.vue
<template>
<div class="navbar">
<nav class = "deep-purple">
<div class="container">
<h1>navbar component loaded</h1>
</div>
</nav>
</div>
</template>
<script>
export default {
name: 'Navbar',
data(){
return{
}
}
}
</script>
<style>
</style>
最佳答案
您的组件位于 data() 函数内。 试试这个:
export default {
name: 'Splash',
components: {
Navbar
}
}
关于javascript - 在组件内嵌套 Vue 组件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54343932/