0

I can nest components within the root App.vue component just fine but if I try and nest a component within a non root component nothing shows up. If I instead nest the Navbar component that wont show up in Splash.vue within App.vue it works, likewise if I move the Footer component to Splash.vue it doesn't.

App.vue (Footer component works fine, router then loads 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 (Navbar component doesnt load, the text does load so I know the router is working correctly)

<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>
6
  • Did you try to nest the Navbar outside the v-container component? Also, does it appear when you debug it with Vue Tools? Commented Jan 24, 2019 at 10:12
  • @niklaz, I think v-container is registered by Vue.use(Vuetify). Commented Jan 24, 2019 at 10:27
  • It is within v-container within Splash.vue as in the example, it also shows up as a component within Vue Tools, just doesn't display. Thanks. Edit: Yes I have tried within and outside of v-container, the result is the same. Commented Jan 24, 2019 at 10:30
  • Can you share Navbar definition? Commented Jan 24, 2019 at 10:32
  • I have updated the main post Commented Jan 24, 2019 at 10:34

1 Answer 1

3

You have your components inside data() function. Try this instead:

   export default {
      name: 'Splash',
      components: {
        Navbar
      } 
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.