Utilizing dynamic text properties within SVG in Vue 2

When rendering a list of icons and setting dynamic text, it appears that the first item's property overrides all others.

Desired outcome:

https://i.sstatic.net/cOG0s.png

Actual outcome:

https://i.sstatic.net/e2XIT.png

Upon inspecting with Vue Devtools, it is confirmed that the correct props are passed to each image component.

Code:

<div>
    <my-component v-for="item in items" :key="item.id" :label="item.number" />
</div>

My-component (only <tspan> tag and x attribute have been modified):

<template>
    <svg
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        width="102"
        height="102"
        viewBox="0 0 102 102"
    >
        <defs>
            <filter
                id="7ojrpldaib"
                width="117.9%"
                height="127.7%"
                x="-8.9%"
                y="-13.9%"
                filterUnits="objectBoundingBox"
            >
            ... (omitted for brevity)
      ...

Answer №1

I have successfully implemented a system to generate random IDs using the labels.

The issue was due to having the same IDs for all the <text> elements.

To fix this, update the code as shown below:

<g fill="#FFF">
    <use filter="url(#s9h21tx5rd)" :xlink:href="`#kj63480c6e${label}`" />
    <use :xlink:href="`#kj63480c6e${label}`" />
</g>
<text :id="`kj63480c6e${label}`" fill="#FFF" font-family="AvenirNext-Bold, Avenir Next" font-size="16" font-weight="bold">
    {{ label }}
    <tspan :x="`${x}`" y="77">
        {{label}}
    </tspan>
</text>

You can find the complete code here if you need to reference it.


The full code for my-component is provided below and can be copied directly:

<template>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="102" height="102"
        viewBox="0 0 102 102">
        (Full SVG Code Here)
    </svg>
</template>
<script>
    // Vue Component Script Goes Here
</script>

For access to the application, click on the following link:

Application URL

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

Unresponsive Radio Buttons in HTML

Have you ever encountered the issue where you can't seem to select radio buttons despite them having a confirmed name attribute? Here is an example of the HTML code: <div id="surveys-list" class="inline col-xs-12"><div> <div class="i ...

How can we eliminate duplicate objects in a JavaScript array by comparing their object keys?

I am trying to remove duplicate objects from an Array. For example, the object 'bison' appears twice. var beasts = [ {'ant':false}, {'bison':true}, {'camel':true}, {'duck':false}, {'bison':false} ...

After clicking, I would like the text from the list item to have a style of "background-color: aqua" when displayed in the textarea

Is there a way to apply a highlight with a style of "background-color: aqua" in the textarea only to the word selected from the list above after clicking on it? See below for my HTML: <head> <script src="https://ajax.googleapis.com/ajax/libs/ ...

What are some ways to incorporate TypeScript into a function component to enforce type constraints and set default values?

I have a function component similar to the example provided. I am familiar with using PropTypes to define prop types and default values in React, but my team has transitioned to TypeScript. Can anyone help me understand how to achieve the same in TypeScrip ...

Discovering the common multiples of two numbers within an array by utilizing the .forEach() method in JavaScript

I have been tasked with looping through an array using the .forEach method in order to return all the values. If any of the numbers are a multiple of 3 or 5, or both 3 and 5, that number must be returned as a string. Here is my current code: let arr = [1, ...

Divide a text containing HTML <br> element into multiple lines

How can I split a string containing HTML break tags into multiple lines and render it as multi-line in the UI? I've tried using the split method but it doesn't seem to work. Any suggestions on how to achieve this without using dangerouslySetInner ...

Troubleshooting server side rendering and Typescript in VueJs: An issue arises

I'm currently working on building a stack with Server Side Rendering (SSR) and Typescript. Things seemed to be going smoothly until I encountered the error: TypeError: Cannot read property 'render' of undefined. Below is the complete stack t ...

The React server-side rendering isn't reflecting changes made on the client-side route

Upon the first refresh, both the server and client side are updated; however, subsequent updates only affect the client side when switching pages with react router. For instance, refreshing the page or entering a new URL causes changes on the server and t ...

My goal is to provide flexibility in updating values through the use of radio buttons, dropdown menus, lists, and other input methods

var trees = []; trees["Furu"] = {1915: 20, 1950: 31, 1970: 53, 1990: 89, 1995: 102, 2000: 117}; trees["Gran"] = {1915: 23, 1950: 39, 1970: 72, 1990: 89, 1995: 92, 2000: 99}; trees["Lauvtre"] = {1915: 4, 1950: 6, 1970: 8, 1990: 12, ...

Best method for extracting content from a tag and storing it in a variable in a Vue component

Looking for the best way to capture user-clicked {{exchange}} in a Vue code snippet <ul> <li v-for="exchange in finalExchanges"><button class="resultBtn"> {{exchange}} <hr></button></li> </ul> The JavaScrip ...

Unlock the Power of Vue Draggable in Vue.js 3 with These Simple Steps

When attempting to implement Draggable in Vue.js 3, I encountered an error message: VueCompilerError: v-slot can only be used on components or <template> tags. Below is a snippet of my code: <draggable tag="transiton-group" name="s ...

Is there a way to create a grid layout rather than just rows in a Vue table?

My Vue template snippet appears as follows: <tr v-for="template in templates" :key="template.id" > <td width="400"> <a @click="create(template.id)" class="hand-hover"> <i :class="`fa fa-${template.icon} fa-fw`"></i&g ...

What is the process of creating groupings within a list using jQuery?

Looking for help with creating sorted groups in jQuery. Here is my code snippet: https://jsbin.com/xabohupuzu/edit?html,js,output $(function(){ var data =['c','d','c','abc','dee','pu','gu& ...

Getting the checkbox count value in a treeview upon successful completion of an AJAX request

After successful JSON Ajax response, a treeview structure with checkboxes is displayed. I need to capture the number of checkboxes checked when the save button is clicked. @model MedeilMVC_CLOUD.Models.UserView <script type="text/javascript"> ...

NodeJS Multer for handling multiple form fields

Dealing with Multer for multiple fields can be a challenge. I am in need of uploading images using the file field for one image, as well as utilizing "Summernote" to upload another image. All of this needs to be handled within one controller. How should ...

Any modifications made to a copied object will result in changes to the original object

The original object is being affected when changes are made to the cloned object. const original = { "appList": [{ "appId": "app-1", "serviceList": [{ "service": "servic ...

Scrolling with animation

While exploring the Snapwiz website, I came across a captivating scroll effect that I would love to implement on my own site. The background picture changes seamlessly as you scroll, with the front image sliding elegantly into view. A similar type of scro ...

Tips for transferring information from Django to React without relying on a database

Currently, I am in the process of developing a dashboard application using Django and React. The data for the user is being pulled from the Dynamics CRM API. To accomplish this, I have implemented a Python function that retrieves all necessary informatio ...

"Exploring the possibilities of Ajax in conjunction with Sol

I recently completed a tutorial on Ajax Solr and followed the instructions in step one. Below is the code I wrote: header.php: <script type="text/javascript" src="static/js/ajax-solr/core/Core.js"></script> <script type="text/javascript" s ...

Issue with method assignment in extending Array class in Typescript

Currently, I am utilizing Typescript and Vue in my workflow, although the specific framework is not a major concern for me. I have been attempting to expand Array functionality in the following manner: class AudioArray extends Array<[number, number]&g ...