Issue with Vue-router: Component not appearing upon initial load

I am currently developing a webpage using vue and vue-router. Here are the routes I have set up:


        import Vue from 'vue'
        import VueRouter from 'vue-router'
        Vue.use(VueRouter)

        import App from './views/App'
        import Home from './views/Home'
        const router = new VueRouter({
            mode: 'history',
            routes: [
                {
                    path: '/',
                    name: 'home',
                    component: Home
                }
            ],
        });
        const app = new Vue({
            el: '#app',
            components : { App },
            router
        });
    

The issue I am facing is that the Home component is not being mounted. Here is the code for the component:


        <template>
            <div class="row">
                .....
            </template>

            <script>
                export default {
                    mounted: function() {
                        console.log('hello')
                    }
                }
            </script>
    

When I add another router and use router-link, the component loads as expected. However, the Home component does not load on the first page load. How can I solve this issue?

My App.vue file consists of a navbar and a footer. Here is the code snippet for the component:


        <template>
            <div>
                .... a navbar ....
                <div class="body z-depth-5">
                    <router-view :key="$route.path" @ajaxover="ajaxOver"></router-view>
                </div>
                .... a footer ....
            </div>
        </template>
        <script>
            import PageLogo from '../components/PageLogo'
            import Loading from '../components/Loading'
            export default {
                mounted : function(){

                },
                components : {
                    'page-logo' : PageLogo,
                    'loading' : Loading
                },
                methods : {
                    ajaxOver : function() {

                }
            }
        </script>
    

Answer №1

Explain the usage of template within the New Vue

In the code snippet below, a new Vue instance is created with the specified properties:
const app = new Vue({
    el: '#app',
    components : { App },
    router,
    template: '<app />'
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remove any stored data and reset to the default state when the component is destroyed, following data retrieval

I need to clear the static data upon component destruction. The data is fetched from a service and currently, I am using the same component for both adding and editing purposes. My goal is to clear the temporary static data once the user has finished editi ...

Dynamic Map Maker with JavaScript

Looking to create a tile map using just one picture for a 5x5 grid of small pictures. I've written some Javascript code with nested loops, but only one picture is showing up. If I remove the br tag in the second loop, I get 5 pictures displayed in a r ...

Retrieve the content of a specific HTML tag using JavaScript

Is it possible to extract the content of a specific HTML tag as a string or XML format? <body> <script src="jquery.min.js"> //var test = document.getElementsByTagName("input"); //alert(test[0]); $(document).ready(function ( ...

The error "TypeError: ollama.chat is not a function" has occurred when trying to use the ollama module in

Currently, I am grappling with a Node.js project that requires me to utilize the ollama module (ollama-js). The problem arises when I invoke the async function chatWithLlama() which contains ollama.chat(), resulting in the following error being thrown: Ty ...

Is there a way to automatically trigger the opening of a Popper upon initial page load?

Discovering the wonders of React and material-ui through https://material-ui.com/components/popper/, I am eager to showcase the Popper without requiring a button click once the page loads. import React from 'react' import Popper from '@mate ...

Automated file uploading with AJAX on Firefox

After inserting a row into the database, I want to automatically upload a PDF/XML file with no user involvement. The script should be able to identify the filename and location of the file. Is there a method to achieve this task? Share your ideas in the a ...

What is the best way to continuously compare two date variables every minute using Javascript?

In my script, I have two date variables - one representing the current time and the other two minutes later. My goal is to compare both values every minute and trigger a function when the current time is greater than or equal to the latter time. Unfortun ...

Using v-model with the Toast-UI editor in Vue.js adds a dynamic and

Is there a way to bind the input value while using toast-ui vue-editor since it doesn't support v-model? Here is my setup for toast-ui: import '@toast-ui/editor/dist/toastui-editor.css'; import { Editor } from '@toast-ui/vue-editor&apos ...

The jScrollPane fails to remain at the bottom

I have implemented jScrollPane for the scrollbars in a chat interface that I created. However, I am facing an issue where the scroll does not automatically go to the bottom as expected. I have set the 'stickToBottom' option to true and also enabl ...

Sending the handleSubmit() function to the child component does not alter the state of the parent component

I just started learning React and Javascript. Currently, I am working on a form where users can specify the details of a "Mob". Upon submitting the form, I anticipate that handleSubmit() (which is passed down from the parent component) will update the sta ...

Learn how to implement interconnected dropdown menus on an html webpage using a combination of JavaScript, AngularJs, and JSON dataset

Incorrect HTML code example: <div ng-app="myApp" ng=controller="myCtrl"> States : <select id="source" name="source"> <option>{{state.name}}</option> </select> Districts: <select id="status" name="status"> ...

Using HTML and JavaScript to shift window positions within the AIR framework

Currently, I am in the process of creating an AIR framework application using HTML and JavaScript/jQuery within Aptana 2.0. To enhance user experience, I have eliminated the toolbox (<systemChrome>none</systemChrome>), but now I am looking to p ...

Error: The function in Knockout js is not defined as undefined

I am attempting to insert specific data into an array, as shown below: Below is my code: Create.html Field Name: Display Name: ...

Getting the id of a single object in a MatTable

I'm currently working on an angular 8 application where I've implemented angular material with MatTableDatasource. My goal is to retrieve the id from the selected object in my list: 0: {id: "e38e3a37-eda5-4010-d656-08d81c0f3353", family ...

The Vue Swiper does not support inline containers in my code

I am facing an issue with the layout of my simple swiper in my vue app. The containers are not inline as expected, causing the second one to appear under the first. Additionally, I am struggling with making the slider element visible only within the viewpo ...

Step-by-step guide on incorporating a hyperlink within a row using @material-ui/data-grid

I am currently using @material-ui/data-grid to showcase some data on my webpage. Each row in the grid must have a link that leads to the next page when clicked. I have all the necessary data ready to be passed, however, I am facing difficulty in creating a ...

Having trouble with Angular's ng-class performance when dealing with a large number of elements in the

I've encountered a performance issue while working on a complex angular page. To demonstrate the problem, I've created a fiddle that can be viewed here. The main cause of the performance problem lies in the ng-class statement which includes a fu ...

Dealing with Form Submission on Enter Keypress in VueJs

Transitioning from Angular to Vue was smooth until I encountered a frustrating issue that seems to have been ignored by VueJS developers. The challenge of allowing users to submit a form by pressing enter from an input field had me pulling my hair out. How ...

"Fading out and triggering the load of the next scene is not functioning properly following the recent update

After updating my storybook app, I encountered a problem with a function that no longer works. The script on the gameobject containing my audio track used to fade the screen to black and load the next scene when the audio track ended. I'm an artist w ...

Loading Angular Controller in a dynamic fashion

I am attempting to dynamically load controllers using ocLazyLoad: $ocLazyLoad.load('./ctrls/login.js'); However, I am encountering an error stating: The controller named 'loginCtrl' is not registered. angular.module('opt ...