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

What could be causing the lack of response from PHP Ajax?

In the midst of tackling my college project, I find myself working on a webpage that is designed to showcase City and temperature information. To accomplish this task, I am delving into the realm of AJAX in order to dynamically update the temperature at sp ...

SignalR's postback interrupts the functionality of jQuery actions

On my screen, I have a widget that updates data and changes its class based on server-side interactions. It also responds to mouse clicks. To notify multiple clients of updates simultaneously, I'm using SignalR. The problem arises when I wrap everythi ...

In what way can I incorporate additional functions or multiple functions within an Express route to modify database information?

Currently, I am working on a project that involves Express and MySQL. One of the challenges I am facing is retrieving data from a connection.query and then utilizing that data in other functions within the same route. My goal is to use the array created in ...

Creating a dropdown menu in Vue.js with a nested array

Upon receiving a response from the Zoho API, I am faced with an array structured as follows: { "response": { "result": [{ "4076840000001": [ { "Department": "Department 1", " ...

Shopify module is throwing an error stating that React is not defined

I wanted to create my first Shopify module, but I encountered an error in my application page on the shop while using React. Here is my index.js code: import {Page} from "@shopify/polaris"; import {ResourcePicker} from "@shopify/app-bridge- ...

Having difficulty transferring user input file from Vue.js to Symfony PHP

Sample text herePlaceholder image descriptionI'm encountering an issue with sending an image file from the frontend (Vue.js) to the backend (PHP Symfony). I have set up a form where users can upload an image file, and now I need to send that file to t ...

Display div content depending on the clicked ID in AngularJS

Unique Header Links HTML <ul ng-controller="pageRouteCtrl"> <li ui-sref-active="active"> <a ui-sref="home" class="" ng-click="getPageId('live-view')">LIVE</a> </li> <li> <a ng-clic ...

Having trouble with UseSelector in React Redux?

I am currently working on a exercise to better understand the react-redux process, but I seem to have hit a roadblock. Any assistance would be greatly appreciated. One interesting observation is that when I subscribe and log the store into the console, it ...

Is there a way to implement the ESC key as a keyboard shortcut in Vue.js or JavaScript?

Is there a way to incorporate keyboard functionality into my vuejs app? I would like for the user to be able to select a button by pressing the ESC key on their keyboard. Specifically, I want the first button with shortKey:1 to be selected. How can I achie ...

Inexplicably, HighCharts flips its axis when exporting data

I am facing an issue with the display of my Highchart in the web application. While it appears correctly in the browser, the exported chart flips the axis and shows a different image. Below are the options I have configured for my Highchart: var options = ...

Exploring the Array Functionality in React

Is there a way to access the lista and add up all the values in unidades when the Producto matches both 1 and 2? [{ "id": "3WzFN", "cliente": "1", "lista": [{ "unidades": "2 ...

Changing route parameters or query parameters does not trigger a reload of component data in React

The "home" component has links that direct to the product component when clicked. Another component always visible displays links to recently visited products. However, on a product page, these links fail to work properly. Although the URL updates and tri ...

The Interactive Menu Toggler: A jQuery Solution

$(window).on('resize', function() { if ( $( window ).width() > 768 ) { $('#menu-main-navigation').show(); } }); $('#nav-toggle').on('click', function() { // start of the nav toggle $('#m ...

Creating structured paths for retrieving data via HTTP GET requests

In my Laravel project, I have routes set up for requests in a traditional way: Route::get('edit/{user}', 'AdminUserController@getUser'); Route::post('delete', 'AdminUserController@deleteUser'); However, I am facing ...

Queue with promises

My challenge is to process an array of files, in batches of N. I have a function called doWork that returns promises. var files = [] var doWork = function(file) { return asyncFn(file) } I want the ability to dynamically add items to this queue. Updat ...

Centering a button within a table-cell through movement

I'm facing an issue with aligning a button placed inside a table cell. The table setup is as follows: <b-table v-if="rows.length" :thead-tr-class="'bug-report-thead'" :tbody-tr-class="'bug-report-tbody& ...

Trouble with HTML2PDF.js - download not being initiated

Currently, I am utilizing html2pdf.js in my project by following this tutorial: https://github.com/eKoopmans/html2pdf.js However, I've encountered an issue where despite implementing everything as instructed, the download prompt for the specified div ...

The one-click button is functional on larger screens, while on mobile devices, only a double click will register

I am facing an issue in angular where a button works perfectly fine with one click on larger screens, such as Macbook. However, on iPhone, it requires a double click to function properly (it works fine on Android too). The alert triggers with a single cl ...

Vuetify Expandable Data Table: Changing the position of the expanded row

Exploring the expandable data table feature in Vuetify, you can find more information in the Vuetify documentation To customize the expanded item, we can utilize the <template v-slot:expanded-item="{ headers }"> template. I have successfully includ ...

The image is experiencing difficulty loading from the Express static directory

Having some trouble with image loading... I've noticed that images are loading fine from the local folder, but not from the uploads folder which is set to be static. I've been attempting to upload a file from the browser. The upload and save pr ...