0

No errors in browser, Webpack compiles successfully, but the "hello from dashboard" doesn't show up in the page.

I'm using Vue v2.6

main.js

import Vue from 'vue'

Vue.component('dashboard', require('@comp/dashboard.vue').default);

const app = require('@/App.vue').default; // this app component works fine

import "./css/app.css"

new Vue({
  render: h => h(app) // this app component works fine
}).$mount('#app')

dashboard.vue

<template>
  <div>
    Hello from dashboard
  </div>
</template>

<script>
export default {
  name: "dashboard"
}
</script>

index.html

<body>
<div id="app">
    <dashboard></dashboard>
</div>
</body>

This is the rendered HTML from the browser, However, "hello from dashboard" is not there :(

<body>
<div id="app">
    <dashboard></dashboard>
</div>
</body>
3
  • i see nothing wrong in your code can you make sandbox for demo.. Commented Aug 25, 2021 at 12:40
  • didnt know a way for online sandbox with bundles and stuff, it is here github.com/Z3yko/vue-app, many thanks Commented Aug 25, 2021 at 13:06
  • 1
    @VishnuBhadoriya You missed the HTML code, it´s wrong to put any kind of code into the <div id="app">, because it will be replaced. So with <dashboard>, that´s why it dont show. Commented Aug 25, 2021 at 19:03

2 Answers 2

2

You have the root file "App.vue" mounted in the div id = "app", so the "dashboard" needs to be added to App.vue to see its contents.

// App.vue
<template>
  <dashboard />
</template>

<script>
  export default {};
</script>

<style scoped></style>

In this code, you have connected a component globally, which will be available in App.vue or another child component

Vue.component('dashboard', require('@comp/dashboard.vue').default);
Sign up to request clarification or add additional context in comments.

3 Comments

Right that's my point, "globaly" so I should be able to use it in index.html also right? why is that not working, and Im registering it to the instance not to App component
you should not use anything inside div#app it will be replaced
@manhoty index.html acts as a start file, in which no application development is carried out, so all the logic and architecture of the application takes place in the src/ folder next to the root App.vue document. Perhaps you want to include vue as a library, then you can use components in html files. For example, how is it herel
0

I assume its the path you are missing so i added a / before comp. Because you stated the App.vue works.

Vue.component('dashboard', require('@/comp/dashboard.vue').default);

1 Comment

thnaks but no im setting the alias this way and it's resolving

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.