Having trouble integrating dynamic CSS with Vue.js

Is there a way for me to apply dynamic styling based on the result within my div?

I have created a function that calculates a total number and updates the data property to display either 'Low' or 'Good' depending on the count.

I have defined two classes for styling:

.good-result {
  color: green;
  font-weight: bold;
}
.poor-result {
  color: orange;
  font-weight: bold;
}

My current implementation of dynamic styling is as follows:

<div class="resultValue">Water intake: <span :class="'Low'?'poor-result' : 'good-result'">{{ resultsWater }}</span></div>

The issue I am facing is that it always applies the .poor-result style, regardless of whether the value in the div is 'Low' or 'Good'.

Answer №1

Attempt the utilization of string interpolation and conduct a comparison between resultsWater and 'Low':

 :class="`${resultsWater === 'Low'?'poor-outcome' : 'good-outcome'}">

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

The process of ensuring a component is able to watch for the router even when it is not within the router

I am facing an issue with setting v-if for an element to get a boolean value from a function when the router changes the URL. Here is the code snippet for my Header component: <template> <header class="wfm-header"> <div class=" ...

Error: ChunkLoadError encountered when trying to load the "blogs-component" chunk in Laravel Vuejs

Despite smooth functioning on local development, my Laravel + Vuejs project is encountering ChunkLoadError on 2 pages. After consulting similar cases on SO and confirming the file's existence in the output path, the issue persists. The affected page ...

Enhancing UI design with Vue.js

I'm attempting to customize elements using data from a JSON file in Vue.js: <div v-for="(item, index) in json._items" class="help-inner-callout" v-html="item.text" style="top:item.top; left: item.left;">&l ...

<H2> along with <Sup>

So I have an H2 heading with a company name and next to that on the same line, we need to include a Superscript tag (TM). Here is the code: <h1 class="Red">Company Name</h1><sup>&#8482;</sup> When rendered, it looks like this: ...

Using the HTML attribute text-overflow: hidden with a dot at the end may not produce the desired results

Currently, I am utilizing a bootstrap card and attempting to enhance the appearance of the lengthy text within the dscrptn_limit class by adding ellipsis at the end. This is my template: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn. ...

I need to know how to create a patch request in Vue.js and simultaneously modify the marks input for specific individuals by using v-model

Hello there, I am currently developing a student assessment input form using vuejs, express, and mongoDB. The backend API is complete and functioning properly when tested with postman. Here is the code: // UPDATE MARKS router.patch('/:studentId' ...

Error: The @use directive must come before any other rules in Angular

Error message: Issue: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): Error Details: HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js) ...

Struggling to minimize the dimensions of the Image div in React Js with Tailwind CSS

I am currently working on replicating the functionality of the Book My show Application. Specifically, I am developing a Cast and Crew slider. Despite my efforts to decrease the size of the images, the spacing between them remains unchanged. Here is my Ja ...

The reactivity of vuex state seems to be lacking

Implementing a loading spinner condition using Vuex to manage loading = true/false across multiple components. LoadingSpinner.vue <template> <fulfilling-square-spinner v-show="loading" class="loading-spinner" :animation-duration="4 ...

Switch the background image to a new one when the checkbox is selected

I am currently working on implementing a fading animation that transitions between background images of a div when a checkbox is checked. You can view a live example here Here is my jQuery code: $(function(){ $('#check').on('change' ...

Similar to the reference of $(this) in jQuery, there is a similar concept in Vue.js

When working with jQuery, the use of $(this) allows for accessing elements without relying on classes or ids. How can we achieve a similar outcome in Vue.js? ...

Sharing data between Vue components

Recently delved into the world of Vue.js and could use some guidance. I've got two components that are not directly connected as parent and child. I attempted passing a variable between the two using "props," but it didn't work out as planned. ...

Ways to allocate space evenly between components of the same size in React Native

As a beginner in Javascript and React-native, I have been experimenting with the technology to assess its viability for potential use in my current workplace. However, I have encountered some challenges with the user interface. To enhance my understanding ...

Is there a way to incorporate pseudo-dynamic css into my projects?

I'm struggling with managing custom colored elements on my website. For instance, I have a hundred navigation squares on the site, each with its own unique color. The only solution I can think of is creating separate CSS classes for each color, but t ...

Utilize custom scrollbar design exclusively for Windows operating system

My goal is to customize the scrollbar style of a div specifically for Windows systems. While most mobile devices have invisible scrollbars that I want to keep hidden, the aesthetics of Mac OS scrollbars are acceptable to me. What I really need is to make t ...

Ways to decrease the saturation of a background image within a div using CSS

I've come across many plugins that can desaturate an image within the tag. However, I haven't been able to find a solution for desaturating a background image that is used for an element (div). Is there a way to desaturate the background image ...

Div behaving as a radio input

I have customized radio buttons to look like buttons using JavaScript. However, on page load, both buttons automatically receive the 'active' class instead of only when they are selected. Additionally, the fadeToggle function in the if-statement ...

How to centrally position a loader inside a div using Bootstrap 5

I recently implemented a loader within a div using the following CSS code: .main-container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100% !important; } .loading { width: 20px; height: 20p ...

"Error: Unable to push new Grade to grades array" encountered while attempting to add a Grade to an existing array

Hi there! I'm working on a webapp that allows me to track my grades and calculate the average, but I'm having trouble adding grades to my Array using a button. Whenever I click on the Add Button, an error message pops up: TypeError: this.grades. ...

The flex box container has an overflowing issue despite the implementation of overflow:hidden and setting a min-width of

Struggling to make my flex box container fit in the div Despite setting min-width: 0 and overflow: hidden as a last resort the flex box simply won't shrink when the width changes Check out what happens when the width is adjusted: https://js ...