Vue 3's "<Component :is="">" feature magically transforms camelCase into lowercase

Within my application, I have implemented a feature where users can customize the appearance of social media links on their page by defining which platforms they want to include. Each social media platform is represented by its own component responsible for generating the link dynamically.

For example:

<script setup>
  import LinkToInstagram from './socialmedia/LinkToInstagram.vue'
  import LinkToFacebook  from './socialmedia/LinkToFacebook.vue'
  //These components will be loaded through an API
  const links = [
    'Instagram',
    'Facebook'
  ]
</script>

<template>
  <span v-for="social in links" :set="currentComponent = 'LinkTo' + social">
    <component :is="currentComponent" show-link-text="true" slug="example" />
  </span>
</template>

<style scoped>
</style>

The expected output should resemble:

<LinkToInstagram show-link-text="true" slug="example"></LinkToInstagram>

And Vue should load the appropriate component accordingly.

However, the current output displays:

<linktoinstagram show-link-text="true" slug="example"></linktoinstagram>

with all lowercase and no functionality.

I attempted using kebab-case without success. When I printed the variable currentComponent, it showed the correct value:

LinkToInstagram (camelCase). Am I using the :is attribute correctly, or am I misunderstanding its purpose?

If I manually code <LinkToInstagram ... />, everything functions as intended.

Answer №1

When importing components, you can easily use them as values:

<script setup>
  import LinkToInstagram from './socialmedia/LinkToInstagram.vue'
  import LinkToFacebook  from './socialmedia/LinkToFacebook.vue'
  //These will be fetched via an API
  const links = [
    'Instagram',
    'Facebook'
  ]
  const componentMap = {
    Instagram: LinkToInstagram,
    Facebook: LinkToFacebook,
  }
</script>

<template>
  <span v-for="link of links" :key="link">
    <component :is="componentMap[link]" show-link-text="true" slug="itest" />
  </span>
</template>

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

Next.js version 14 is having difficulties displaying the loading.tsx file

click here for image description Why is the loading not displaying when navigating to /profile? How can I fix this issue? export default function Loading() { // You can add any UI inside Loading, including a Skeleton. return ( <div> lo ...

Controlling user login sessions and cookies with angular.js is essential for ensuring secure and seamless

I have a login application where I need to implement session and cookies using angular.js. Below is the code for my login functionality. loginController.js: var loginAdmin=angular.module('Channabasavashwara'); loginAdmin.controller('log ...

Retrieve the function-level variable within the while loop's else statement

Struggling with node.js, I find myself facing the challenge of accessing a variable declared at the start of a function from an else statement nested within a do while loop: function myFunction(){ var limit = 2000; var count; var total; va ...

What is the best way to update a nested property in an object?

Consider the following object: myObject{ name: '...', label: '...', menuSettings: { rightAlignment: true, colours: [...], }, } I want to change the value of rightAlignment to fals ...

Modifying Parent Component Layout Using Vue.js

I am currently in the process of converting a UI element into a component for the purpose of reuse. This particular element consists of two buttons that toggle the visibility of two DOM elements within the parent app. The state of these buttons is stored i ...

Laravel displays a 404 error page following modifications made in sessions

I seem to be encountering a peculiar problem. I am forcefully logging in the user and storing some information in the session. However, after doing so, I encounter a 404 error. Despite checking the logs, I am unable to determine what is causing this issu ...

What is the best way to maintain an ongoing sum of multiple values using bacon.js?

Experimenting with the power of bacon.js. I want to maintain a dynamic total of values from a set of text inputs. The example on the github page utilizes the .scan method along with an adding function, which functions well for simple increment and decremen ...

NodeJS and ExpressJS fail to redirect to the main landing page

I am currently developing a shopping cart application using nodejs/expressjs. I have encountered an issue with redirecting back to the homepage ('/') after the user submits their credentials during sign up. Despite my search for relevant articles ...

Wondering how to optimize FullCalendar for mobile and touch events?

I am looking to incorporate a drop event feature into the mobile version of fullcalendar. To achieve this, I am utilizing Jquery UI Touch Punch. After researching on various platforms such as Stack Overflow 1, Stack Overflow 2, Stack Overflow 3, Stack Ove ...

Removing dynamic input fields with VueJS

Need some help with deleting fields in Vue. Managed to get them to render, but not sure how to remove them. I added an index option in the v-for directives, but now I'm stuck. Any suggestions would be appreciated! If you want to see my code in action ...

What steps can be taken to ensure express Node.JS replies to a request efficiently during periods of high workload

I am currently developing a Node.js web processor that takes approximately 1 minute to process. I make a POST request to my server and then retrieve the status using a GET request. Here is a simplified version of my code: // Setting up Express const app = ...

Traversing a hierarchical structure and building a REACT user interface based on it

Currently, I am tasked with a project that involves working with a hierarchy tree. The goal is to loop through the data provided by the tree and create a user-friendly UI representation of the hierarchy for seamless navigation. Here's an illustration ...

Ensure the sum is recalculated whenever the input changes by using the jQuery change event

I am creating a system that requires the total values of multiple inputs to not exceed 100. I have successfully implemented this functionality, but now I need a way to automatically adjust the total if changing one input causes it to drop below 100. Here& ...

ReferenceError: webpackJsonp Error in Vue Js is not handled

I am encountering an Uncaught ReferenceError: webpackJsonp in Vue Js all of a sudden. Although I am new to Js, I have recently started working on Vue applications. I have attempted various solutions from Git and stackoverflow but none of them seem to be ef ...

Comparing strings with if-else statement

I am having trouble comparing strings in this array. For some reason, the strings are never equal. var person = ["Sam", "John", "Mary", "Liz"]; var searchedName = prompt("Enter name"); var resultMessage = ""; for (index in person) { var currentName = ...

What is the best way to delay the rendering of my Vue component until a function call is finished?

After extensive research online, I have been unable to discover a specific solution to my issue. The problem is that I have a Vue component that relies on an init call and I need it to avoid rendering until the call is successfully completed. Once the ca ...

Is it feasible to utilize the translate function twice on a single element?

Using Javascript, I successfully translated a circle from the center of the canvas to the upper left. Now, my aim is to create a function that randomly selects coordinates within the canvas and translates the object accordingly. However, I'm encounter ...

The ExpressJS Req.method TypeError occurs when attempting to read the 'method' property of an undefined object

My node express server is throwing an error: Error in index.js. const bodyParser = require('body-parser'), express = require('express'), path = require('path'); const config = require('./config'); con ...

Is it possible to use a v-for loop within F7+Vue to dynamically update the title of each accordion item?

Is there a way to dynamically update the title of each accordion-item using a v-for loop in F7+Vue? I want the title of each accordion-item to match the Title property of the objects in my myList array that is being iterated through. Here is an example: ...

Issue with JSON parsing on non-Chrome web browsers

Encountering a problem with parsing fetched JSON data from browsers other than Chrome, Firefox providing error message: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data". Notably, code functions in local node.js environmen ...