0

I wrote a very simple vue.js application to learn how to work with vue files.

Here is the code:

App.vue

<template>
    <article></article>
</template>

<script>

export default {
    data: function() {
        return {

        }
    }
}
</script>

<style>

</style>

main.js:

import Vue from 'vue'
import App from './App.vue'
import Article from './Article.vue';

Vue.config.productionTip = false;

Vue.component('article', Article);

new Vue({
  render: h => h(App),
}).$mount('#app');

Article.vue:

<template>
    <div>
        <h1>bla bla</h1>
    </div>
</template>

<script>
    export default {
        data() {
            return {

            };
        }
    }
</script>

I expect to see 'bla bla' in the browser. However, when I open the browser, I see white page. The console says:

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

and when I open Vue dev tools this is what I see: enter image description here

No Article component has been added. Do you know how to solve it?

3 Answers 3

1

Don't use the html tag article as a component name. Rename it and it should render.

For example:

Vue.config.productionTip = false;

Vue.component('article2', {
  template: '<div>Hi there</div>'
});

Vue.component('app', {
  template: '<article2></article2>'
})

new Vue({
  render: h => h('app'),
}).$mount('#app');
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app"></div>

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

Comments

0

Call components in main.js not the best structure + you don't call him in Vue instance, example:

Article.vue

<template>
    <div>
        <h1>bla bla</h1>
    </div>
</template>

<script>
    export default {
        name: 'article'
    }
</script>

App.vue

<template>
    <article></article>
</template>

<script>
import article from './Article';

export default {
    components: {
      article,
   },
}
</script>

main.js

import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false;

new Vue({
  render: h => h(App),
}).$mount('#app');

I hope this work with you.

Comments

0

It's because you're just rendering App:

render: h => h(App),

You should rather import Article in App and use like:

<template>
    <article></article>
</template>

<script>
import Article from './Article.vue'
export default {
    components: { article: Article },
    data: function() {
        return {

        }
    }
}
</script>

And remove the followings from App:

import Article from './Article.vue';

Vue.config.productionTip = false;

Vue.component('article', Article);

But article is html5 element, so I suggest you to use another name like:

components: {
  myArticle: Article
}

<my-article></my-article>

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.