0
votes

I am using Vue.js and I want to try to render components but it isn't working

main.js:

import Vue from 'vue';
import 'bulma';
import Navbar from './Navbar.vue';

Vue.component('navbar', Navbar);
const MyC = Vue.component('myc', {
  template: '<h1>Are you working?</h1>',
});

const root = new Vue({
  el: '#app',
  components: {
    Navbar, MyC,
  },
});

index.html

<body>
  <div id="app">
    <navbar></navbar>
    <myc></myc>
  </div>
  <script src="dist/build.js"></script> <!-- Webpack endpoint -->
</body>

Navbar.vue

<template>
<h1>HELLO FROM NAVBAR</h1>
</template>

<script>
// Some logic here

export default {
  name: 'navbar',
};

</script>

I coded as written in guide but neither of the ways to render a component is working

I just have blank page

I am using webpack+vue-loader

[UPDATE]

It works without components imports just rendering template

[UPDATE 2]

Got this message

[Vue warn]: Unknown custom element: <navbar> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

2
you're not getting any errors?thanksd
No, even if i use template: '<h1>Hello</h1>' in Vue options it doesn't appearNick Gant

2 Answers

1
votes

move your code from index.html to app.vue, index.html is a html file but not a vue file

try it , now it will be work , happy life.

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

Vue.component('myc', {  //gobal components
  template: '<h1>Are you working?</h1>',
})

new Vue({
    el: '#app',
    template: '<App><App/>',
    components: {
        App
    }
})

//index.html
<body>
  <div id="app">
  </div>
  <script src="dist/build.js"></script>
</body>

//app.js
<template>
    <div class="app">
        <navbar></navbar>
        <myc></myc>
    <div
</template>

<script>
     import navbar from 'path of Navbar.vue'  //local components
     export default {
       name: 'app',
       component:{
         navbar
       }
     }
</script>
0
votes

I've moved everything to App.vue

render: h => h(App) worked for me