What could be the reason for vue-router not displaying the component?

Note: This code is intended for private use only and may contain bugs

I am developing a component loader without using webpack or similar tools.

My issue lies with the getComponents() function, which successfully returns HTML code as a string. However, when I navigate to /userlists, the router does not display anything. Surprisingly, the route / works just fine. Can anyone help me identify my mistake?

Loader:

const getComponent = name => {
    return document.getElementsByClassName('component '+name)[0].outerHTML
}

const mainComponent = {
    template: '<h3>Hand mailer<p>)</p></h3>'
}

const userLists = {
    template: getComponent('userslist')
}

Component:

<div class="component userlists">
        <p>
            Hello vue!
        </p>
    </div>

Router:

const router = new VueRouter({
    hashbang: true,
    routes: [
        {
            path: '/',
            component: mainComponent
        },
        {
            path: '/userlists',
            component: userLists
        }
    ]
})

Answer №1

Oops, I mistakenly included the CSS property display: none; in my class components.

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

Creating an Angular table with dynamic column headers

While working on an angular app to showcase data from different sources, I set up a JSON file with a list of various data sources along with their respective values. Here's an example: var configurableConfigurations=[ { name:"Locations", ...

Tips for obtaining the identifier of a div element while employing the bind() function in jQuery

Imagine having the following div. <div id="456" class="xyz">Lorem Ipsum</div> If I want to execute a function when this specific div is hovered over, I can achieve it like this: $(".xyz").bind({ mouseenter : AnotherFunction(id) }); Prio ...

Reposition buttons using JavaScript

I attempted to modify the button that appears at the top of an HTML page. <div class='play'> <input id="play" type="button" value="Play" onclick="mode('play');startSlideshow();" /> </div> <div class='pause ...

When utilizing a computed property that accesses the Vuex state, the v-if directive alone may not function as expected without

Uncertain of the source of the issue, but the basic v-if functionality seems to be malfunctioning. <template> <div> <select v-model="col.code"> <option v-for="i in foo" :value="i.code" ...

Utilize route parameters in the nested subRoutes object in Vue.js to easily access data specific to

Is there a way to directly access the route params within the route objects? I need to load different components based on the route object. router.map({ '/dashboard/*': { component: Home }, '/dashboard/:module': { compone ...

Encountering TS9006 error while working on a Vue2 Vite project with a combination of TypeScript and

I am in the process of updating an older Vue2 webpack (JS) project to Vite, which involves a mix of JS and TS. Additionally, I am transitioning from using Vuex to Pinia. store.ts interface UserLoginRequestI { emailOrUsername?: string; password?: s ...

Tips for using jquery and ajax to upload a file

I am currently attempting to use AJAX to upload a file along with other form data. I am utilizing this bootstrap and jQuery plugin as a guide. However, while I can successfully submit the form without uploading a file, I am encountering some challenges whe ...

Applying a class change in Vue.js upon mounting

How can I make a button element with a .hover property trigger the hover animation as soon as the page loads? I want to apply a class to the button when the page is mounted and then remove it later. What is the best approach for this? I considered using a ...

Typing in Text within Kendo Textbox using Protractor

I'm encountering an issue with Protractor while trying to input text into a Kendo TextBox. The error message I receive is "ElementNotVisibleError: element not visible". Interestingly, when the text box is clicked on, the "style="display: none;" change ...

A clever way to transfer the "HTML SELECT VALUE" to a different webpage using ajax without the need to refresh the page

Having trouble sending a selected value to another webpage without refreshing? I tried using ajax but couldn't get it to work. After the alert, it seems to stop functioning. Here's the script in one file, where I'm trying to send values 0, 2 ...

Working effectively with Django template variables and JavaScript

Can someone assist me with this issue I am having in my code? I have a Django template variable {% clients_list %} I need to populate multiple select boxes with the same prefixes. This is the code snippet I currently have: $(document).ready(function ...

Attempting to convert PHP tables into PDF format by utilizing jsPDF-auto-table to generate a beautifully structured PDF file containing the results of a PHP query with multiple records

I'm new to stackoverflow but I find myself visiting it regularly for helpful tips. I've taken some code from the simple.html file that comes with the jsPDF auto-table plugin. However, I'm having trouble making it work with data generated by ...

Exploring and Presenting Database Findings (PHP MySQL) in a Format Beyond Traditional Tables in HTML

My code is functioning as intended, where a search is performed in the table based on user input, displaying the attributes within an HTML table. For a clearer picture, I will provide an image of the search output: Output of the Search However, due to the ...

What is the best way to implement jQuery after new elements have been added to the DOM?

I'm currently working on a Sentence Generator project. The program is designed to take a list of words and retrieve sentences from sentence.yourdictionary.com based on those words. The first sentence fetched from the website is displayed using the cod ...

What is the best way to ensure that an array containing hex colors is accurate and filter out any incorrect values?

I am currently only checking if values are not null or undefined, but I want to ensure that each hex color is correct. If a hex color is incorrect, I need to discard it and move on to the next one. If the format is completely wrong, then I should reset to ...

Error: React encountered an unexpected symbol '<' in the code

function SubmitButton(){ return ( <button>Submit</button> ); } Hello everyone! I'm a beginner trying to create a dropdown menu for users to choose a year and then click on the "Submit" button. However, I'm encountering a syntax error ...

What method can be used to implement an alert on a disabled asp.net drop-down menu?

I currently have a drop-down element set up like this: <asp:DropDownList ID="cboJPRem" class="jprem" runat="server"> <asp:ListItem Value="None" Selected="True" Text="None"></asp:ListItem> <asp:ListItem Value="1da ...

Is it possible to assign a class or id to a dynamically inserted link using JavaScript?

Currently, I have code that effectively inserts a link to the selected text: document.execCommand('CreateLink', false, 'link.com') Although this method works well, I am eager to include a class/id for the link to simplify styling it w ...

Calculating the required force vector to score a basketball shot using Ammo.js and Three.js

Currently in the process of developing a basketball game using three.js and ammo.js. The positions of the hoop/rim and ball are constantly changing, making the shots dynamic and relative. I am tasked with determining the correct force vector needed for a ...

I successfully implemented an image tag using JavaScript, however, the image is not showing up on the webpage

When I click the add button in my PHTML file, I want to display an image of the selected fruit in a <div>. function moveoutid() { var sda = document.getElementById('availableFruits'); var len = sda.length; var sda1 = document.getElem ...