0

I have the following...

main.vue

<template>
    <div>
        <header></header>
    </div>
</template>
<script>
    export default {}
</script>

header.vue

<template>
    <div>{{ message }}</div>
</template>
<script>
    export default {
        data: () => {
            return {
                message: 'Dashboard'
            }
        }
   };
</script>

main.js

import Vue from 'vue';
import Header from './header.vue'
import App from './main.vue'
Vue.component("header", Header);
new Vue(App).$mount('#km-viewport')

But when I run this the header component is never rendered. What am I missing? Does using the vue-template webpack plugin require something special here?

I have looked at a couple similar stack overflows and I have tried to use components: { Header } instead but that still doesn't work.

I also tried...

main.vue

<template>
    <div>
        <header></header>
    </div>
</template>
<script>
    import Header from './header.vue'
    export default {
      components:{
        "header": Header
      }
    }
</script>

header.vue

<template>
    <div>{{ message }}</div>
</template>
<script>
    export default {
        data: () => {
            return {
                message: 'Dashboard'
            }
        }
   };
</script>

main.js

import Vue from 'vue';
import App from './main.vue'
Vue.component("header", Header);
new Vue(App).$mount('#km-viewport')
2
  • 1
    Where's the import Header from './header.vue', you have one, don't you? Commented Mar 7, 2018 at 0:03
  • Sorry it is in the main.js I deleted it on accident when copying but that doesn't fix it. Commented Mar 7, 2018 at 14:03

1 Answer 1

1

Yours is a frequent problem:

[Vue warn]: Do not use built-in or reserved HTML elements as component id: name

In your case <header> is a reserved HTML element.

The same happens to <main>, <article> and so on.


Solution: Rename your header component to other name.

Example (I renamed header to header2):

main.vue

<template>
    <div>
        <header2></header2>
    </div>
</template>
<script>
    import Header from './header.vue'
    export default {
      components:{
        "header2": Header
      }
    }
</script>

header.vue

<template>
    <div>{{ message }}</div>
</template>
<script>
    export default {
        data() {
            return {
                message: 'Dashboard'
            }
        }
   };
</script>

Bonus: Don't use arrow functions as in data: () => {, that will give you problems. Use like data() {. This rule applies to methods, computeds, watchers and all other Vue instance options.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this by adding a prefix like you suggest but it still isn't working.
What prefix? Did I suggest a prefix?
kinda instead of adding a postfix (your suggestion with the 2) I created a prefix (my-header). This is since according to the HTML spec they are supposed to be prefixed

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.