Combine Template Components using a plus sign "+"

Is there a method to merge template elements together? I've created this loop template, but I'm struggling to concatenate or join multiple items. When I try placing the + within the <kbd> tag, an extra + ends up at the end and it remains inside the kbd tag (I want it outside of the tag).

<template>
  <kbd v-for="(v, i) in item" :key="i">{{ v }}</kbd>
</template>

The data structure I am working with looks something like this (I'm actually using a store):

data: () {
  return {
    item: [ 'a', 'b', 'c' ]
  }
}

The desired output that I am aiming for is:

<kbd>a</kbd> + <kbd>b</kbd> + <kbd>c</kbd> 

Answer №1

Simple as pie. Conditional rendering depending on the index. This snippet of code should do the trick:

<template v-for="(value, index) in items">
  {{index > 0 ? ' + ' : ''}}<kbd :key="index">{{ value }}</kbd>
</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

Executing the JavaScript code to open the modal dialog

I have created a Modal Dialog (popup) using only CSS3 on my asp page for user registration: HTML : <%-- Modal PopUp starts here--%> <div id="openModal" class="modalDialog"> <div> <a href="#close" title="Close" class="clo ...

Discover how a universal Windows application utilizes webview to access Google Maps events

In the process of developing a Universal Windows App (UWA), I have integrated Google Maps using a webview. Using JavaScript and InvokeScriptAsync, I am able to add and remove markers on the map. Now, I am looking to handle events in the opposite direction ...

Instructions for utilizing Pinia alongside defineCustomElement in Vue 3

Has anyone tried incorporating the pinia store directly into a component as an element? I attempted to do so, but encountered the following error in the developer console: index.8ec3cfca.js:1 TypeError: Cannot read properties of undefined (reading '_ ...

Child functional component does not refresh after its props are altered by its parent component

Looking at the following code: MainParentComponent.js let data = 0; function MainParentComponent() { function handleClick() { data++; } return (<> <button onClick={handleClick}>Increase</button> < ...

Tips on aligning a span element at the center of an image without losing its mouseover

<div class="pic"> <img src="image.jpg" height="250"/> <span class="text" style="display:none">text here</span> </div> <scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </scrip ...

Using Phoenix Channels and Sockets in an Angular 2 application: A comprehensive guide

My backend is built with Elixir / Phoenix and my frontend is built with Angular 2 (Typescript, Brunch.io for building, ES6). I'm eager to start using Phoenix Channels but I'm struggling to integrate the Phoenix Javascript Client into my frontend. ...

Unable to locate module in Vue.js when using browserify

When trying to use almost every npm package with vue.js 1.0, I keep encountering this frustrating error: { Error: Cannot find module '!!./../../../node_modules/css-loader/index.js!./../../../node_modules/vue-loader/lib/style-rewriter.js!./../../../no ...

Web API security concern arises in the spa app. Is it possible for a user who is logged in with a JWT to send arbitrary requests to the API

I have some concerns regarding the security of a Single Page Application (SPA) that I am developing. What measures are in place to prevent an end user from accessing my Web API using a token they obtained? For instance, as an end user of a SPA web applic ...

The functionality of the Angular ng-bind-html directive may be unreliable in specific scenarios

I've exhausted all the solutions found on stack overflow but still haven't found a solution. Using angular 1.4.4 and ng-repeat directive, I am attempting to display a HTML comment inside a table row. A sample comment looks like 'Test commen ...

What is the best way to ensure that a checkbox remains checked with the stored value even after refreshing the page?

Is there a way to keep the value stored in a div when a checkbox is checked, even after the page refreshes? Below is the HTML code: <form name="formProductsFilter" id="formProductsFilter" action="glasses-list ...

I am attempting to retrieve the aria-expanded value using JavaScript, however, I keep receiving an "undefined" response

I'm attempting to dynamically change the class of a <span> element based on the value of the attribute aria-expanded. However, I am encountering an issue where it returns "undefined" instead of the expected value of true or false. Below is the ...

Hold tight for the response from the AngularJS factory request

In my Rails application, I am incorporating Angular. The code snippet below shows an API request being made and the code in the .run function being executed. Sometimes, the API response is still pending when the code is executed. This leads to issues with ...

Having issues with custom directives not functioning properly within AngularJS' RouteProvider

Currently, I'm in the process of learning AngularJS and specifically focusing on the route provider feature. I have successfully built a few pages that functioned well independently. Now, my aim is to implement the route provider into my project. In m ...

Making adjustments to a row in the free jqGrid is a breeze with the ability

Using free jqGrid 4.12.1, I aim to incorporate functionality for adding, editing, and deleting rows in the grid with server-side calls for each operation. Below is the implementation of editurl and 'actions' formatter, { name: "actions", wi ...

Keep the footer fixed at the bottom until the document height exceeds the viewport height

UPDATE Originally flagged as a duplicate, I mistakenly labeled it before actually testing the solution in the linked question. The provided answer did not meet my specific requirement of having a sticky footer that only floats to the bottom of the page wh ...

Ending a message with ellipses once it reaches a predetermined character count

Is there a way for my input field to display ellipsis (...) at the end of my text once it reaches a specific character limit? I've heard about the Substring function, but I'm not sure how to implement it. Below is the input field with a data-li ...

Guide on displaying the AJAX response within an HTML or JSP element pulled from a database

description of image 1description of image 2How can I display an AJAX response from a database (map) on a JSP screen? I am able to retrieve the response in the browser console but unsure how to visually render it on the JSP page, like in a table or any ot ...

Using Typescript, Angular, and Rxjs to retrieve multiple HttpClients

I am looking to send get requests to multiple endpoints simultaneously, but I want to collect all the responses at once. Currently, this is how a single endpoint request is handled: public getTasks(): Observable<any> { this.logger.info('Ta ...

Implementing seamless redirection to the login page with Passport in Node.js

I have encountered a persistent issue while using node.js, express, and passport. After successfully validating the user with passport, my application keeps redirecting back to the login page instead of rendering the index page. Is there a problem with the ...

False Behavior of True in JavaScript Array Testing

Currently, I am working on creating a Node.js multiplayer poker game and encountering various challenges. One significant issue involves identifying a Straight hand from an array in the code provided below. The problem lies in the code's lack of unive ...