What has become of this v-for command?

I had the idea to create an object like this:

So, I started with the following code:

<div class="p-2 border-2 border-blue-300 mr-auto rounded-full space-x-1">
    <button class="text-white w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-yellow-400 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-orange-400 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-green-800 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-sky-500 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-red-500 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-purple-600 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-gray-300 w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
    <button class="text-black w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue"><i class="fa-solid fa-circle"></i></button>
</div>

However, I realized that this approach was not efficient. So, I decided to simplify it using the v-for directive like this:

In template

<div class="p-2 border-2 border-blue-300 mr-auto rounded-full space-x-1">
    <button v-for="level in LevelList" :key="level" :class="`text-${level} w-7 border-2 border-BgLightBlue rounded-full hover:border-primary hover:bg-BgLightBlue`"><i class="fa-solid fa-circle"></i></button>
</div>

In script

export default {
    setup() {

        const LevelList = ['white', 'yellow-400', 'orange-400', 'green-800', 'sky-500', 'red-500', 'purple-600', 'gray-300', 'black']

        return {
            LevelList,
        }
    }
}

After implementing this change, I noticed that the result was different. When I ran 'npm run dev', the output appeared as follows:

Am I missing something?

Answer №1

After analyzing the situation, it appears that this issue is occurring with all elements in the LevelList that have a dash in their name.

There is a possibility that JavaScript is interpreting names like yellow-400 as mathematical expressions, such as (value of yellow) - 400, instead of just treating them as simple strings.

Perhaps try renaming your multi-word elements and observe if this resolves the problem!

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

Ways to refresh a webxr session while clearing all models from the scene

Whenever the webxr session restarts, I notice that two instances of previous objects appear on the screen. I want the screen to be clear when the session restarts. Currently, I am using the following code: for( var i = scene.children.length - 1; i >= 0 ...

Selenium: Locating the element correctly, yet unable to perform interactions with the input field

When trying to interact with an input field using the provided script: from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_ ...

Axe developer tool alert: The <ul> and <ol> elements should only have direct child elements that are <li>, <script>, or <template>

Check out this code snippet. The Li element is built into the <b-navbar> component, but I'm not sure where to locate it in the HTML. <div> <b-navbar type="light" variant="light"> <b-nav-form> < ...

SASS fails to recognize the variable

I am trying to incorporate borders based on specific @media breakpoints. Here is the code I have written: @media(max-width:767px) { $height: auto; $grid: 1; } @media(min-width: 768px) and (max-width:991px) { $height: 370px; $grid: 2; } @media(min-width: 9 ...

What's the best way to show black text for progress between 0-40% and white for progress between 60-100%?

As a beginner, I humbly ask for your forgiveness. My goal is to show progress percentages in black and white based on the progress state. Despite my attempts with if statements and creating new classes for black and white progress states, I have not been s ...

Sorry, there was an error with Vue-i18n: Unable to access the 'config' property because it is undefined

Let's start by examining what functions correctly in App.js import router from './routes.js'; import VueI18n from 'vue-i18n'; const messages = { en: { message: { hello: 'hello world' } } } // Create ...

What is the best way to ensure uniform lengths for both labels and inputs?

Currently, I am in the process of developing a web app using razor pages. My main focus is on the front end (*.cshtml) where I have integrated 4 objects, each consisting of a label and two inputs. My aim is to have all three components appear in line, with ...

What steps can I take to ensure that my progress bar updates and loads automatically?

My progress bar only starts working when clicked, and it doesn't refresh automatically. Is there a way to make it refresh and load automatically without requiring user interaction? Here is the code that I am currently using. Any help would be greatly ...

Tips for converting response text into HTML code

I am receiving a text response like this <span class='text-4xl'>description1</span> When I display it on the screen: import React,{useContext, useEffect} from 'react'; import blogsContext from '../context/blogsCon ...

The Font Awesome icon is not displaying on top of the Materialize CSS progress/determinate bar

I am struggling to display a Font Awesome icon on top of a Materialize CSS progress/determinate div. Unfortunately, the icon is not fully visible and part of it gets clipped or hidden. Despite trying various solutions, I have not been successful. .progres ...

When you hit the refresh button, the vue router automatically redirects you back to

I've encountered an issue with my vuejs project involving the use of vue router in a single page application. While I am able to navigate to different pages using vue router, whenever I reload the page at any route, it ends up redirecting me back to t ...

Using the background-cover property in Chrome may create an extra 1px blank line

My div has a background-cover attached to it, but I'm having issues with Chrome as it sometimes adds a blank line (either horizontal or vertical, depending on the image). Here is my HTML code: <div class="div_image"></div> And here is m ...

Incorporating components into Vue while utilizing Flask poses a challenge

Currently, I am working on a project that involves Flask and Vue. I am attempting to add a carousel to my website, but I am running into difficulties with creating and importing components for Vue when following tutorials. Here is my current file structure ...

Content of reusable angular form is not visible on the homepage

I am currently working on creating a reusable Angular form within an Ionic application. Despite following various tutorials and Stack Overflow posts, I have resolved all errors but unfortunately, the content does not display on the parent page. Here is my ...

What causes the ignoring of config.proxy in axios requests while working on a webpack project?

My objective I am aiming to make a request using [email protected] with full efficiency through an http proxy (squid). My project is built on Vue and uses the webpack template. I initialized it with vue init webpack proxytest The challenge Despite ...

Tips for adding a progress bar to your sidebar

I have a query regarding how to expand the width of a div within an li element. Essentially, as a user scrolls, the sidebar on the right-hand side will cause the span element (highlighted with a red background color) inside the li to transition from 0 to ...

Guiding user to their destination after signing in

Having trouble showing different headers based on user login status? Users can log in using login.php, but you're struggling to display header.php when a user is not logged in or logged in. You want the page to show profile form content when they are ...

Scaling Youtube video backgrounds with Squarespace

How can I inject a code into Squarespace to scale a video as the background and still keep the navigation functional? Here is the current code I am using: <div style="position: fixed; z-index: 50; width: 100%; height: 100%"> <iframe frameborder= ...

Safari 10 experiencing issues with overflow and flex combination

I seem to be facing issues with the flex + overflow combination while testing in Safari. For reference, here is the JSFiddle link: https://jsfiddle.net/9dtrr84c/2/ <div class="container-fluid"> <div class="row parent"> <div class="co ...

Using Javascript to delete an HTML list

Currently, I am working on a webpage that includes notifications along with options to mark them as read individually or all at once. However, when attempting to use my loop function to mark all notifications as read, I noticed an issue. let markAllAsRead ...