Adding a touch of flair to your Vue-i18n parameter

If the template has the following translation:

<p>
{{ $t('Counter: {n}', {n: counter}) }}
</p>

where counter is a number returned from the script, I want to style the variable "n" (for example, make it red).

Is there a way to accomplish this?

Answer №1

To enhance the translation, one method could involve directly inserting HTML code. This will consistently display the counter in red:

translation:

counter: 'Counter is: <span style="color: red">{n}</span>'

template:

<span v-html="$t('counter', {n: 22})" />

If you prefer more versatility when it comes to color selection, you can include an extra parameter:

<span v-html="$t('counter', {n: 22, color: 'green'})" />
counter: 'Counter is: <span style="color: {color}">{n}</span>'

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

Generate a division element that inherits the attributes specified by its unique identifier

I have a div element that dynamically fetches information (rss feeds) based on its id (id="rss-feeds") using the jQuery-rss plugin as shown below jQuery(function($) { $("#rss-feeds").rss("http://feeds.feedburner.com/tar-home?format=xml", { limit ...

How to line up scrollable tables columns with the header using CSS

Link to JsFiddle : http://jsfiddle.net/gfy4pwrr/1 <table cellspacing="0" cellpadding="0" border="0" width="325" > <tr> <td> <table cellspacing="0" cellpadding="1" border="1" width="300" > <tr> ...

CSS: Overlapping pop-up obscuring another element

I am having an issue with my pop-up appearing behind another control, specifically an auto-complete text box. <div id="navTarget"> <ul class="menuTarget"> <li><a href="#"&g ...

Having trouble with less.modifyVars not functioning properly in Visual Studio?

I attempted to dynamically change the LESS variable using HTML within an AngularJS function. The code worked fine on XAMPP with simple HTML and CSS, but when I transferred it to an enterprise app in Visual Studio, it stopped functioning properly. While the ...

A difference in the way content is displayed on Firefox compared to Chrome, Edge, and Safari

Recently, I encountered an issue with a tool I had developed for generating printable images for Cross-Stitch work. The tool was originally designed to work on Firefox but is now only functioning properly on that browser. The problem at hand is whether th ...

Changing the width of an HTML table does not produce any noticeable results

I attempted to create a striped table with 5 columns. The desired column sizes are: 10% width --- 10% width --- 40% width --- 20% width --- 20% width However, my current code is not achieving the correct widths (the 'description' column does n ...

Is it possible to enter NaN in Vue3?

Is there a way to handle NaN values and keep a field blank instead when calculating margins with a formula? https://i.stack.imgur.com/JvIRQ.png Template <form> <div class="row"> <div class="mb-3 col-sm ...

Is there a way to ensure that this image completely fills the container?

I am facing an issue with my code snippet. Whenever I input a large amount of text, it causes the entire row to be pushed down, resulting in extra space underneath the image. How can I ensure that the image always fills its container and adjusts its height ...

What is the best way to eliminate the gap beneath v-app-bar in Vue.js?

Is there a way to eliminate the space below v-app-bar? the header segment User_Header.vue <template> <v-app id="user_header"> <v-app-bar app color="#8a0303" dark> <h1>this is app bar</h1> & ...

Can a pledge be honored at a precise moment?

I have implemented transitions on my web page. When clicked, everything fades out to an opacity of 0 over a duration of 1 second. Then, a new page is swapped in and everything fades back in to an opacity of 1 over another 1-second duration. The issue aris ...

The thickness of an SVG line increases as it is rotated

I am working with multiple straight lines and have specified the stroke-width as 4. However, when I attempt to rotate them, the lines appear thicker than expected. Additionally, setting a negative value, such as <path d="M0 -10 20 0" stroke-width="4" st ...

What is the process of adding a source map for a CSS minification script generated by a gulp task?

Currently, I am focused on optimizing CSS minification through the use of gulp. An issue arises when trying to debug CSS, as all stylesheets are contained within knx.dev.css. It is necessary to implement a solution that allows for easy tracing back to the ...

CSS Vertical Accordion Menu

I am struggling to modify the vertical accordion menu CSS. I am having difficulty adjusting the sub-menu list items. <div id="menuleft"> <div class="top">header</div> <ul> <li><a href="#">Main 1</a> ...

How come the display is not aligned correctly when using display: inline-block along with text?

Could someone explain why a div with display: inline-block aligns differently when there is text or another element inside it? I know that vertical-align can fix this issue, but I'm curious to understand how the browser makes its decision on how to di ...

Sorting through a table based on the name of the element

I am currently working on filtering an HTML table using a search form. It's working great, but I'm facing an issue where the filtered elements are trying to fill the entire width of the table instead of maintaining their original width (which is ...

Trouble with the onload function in onMounted vue3

For my vue3 component, I need to load certain scripts. Here is what I am currently implementing: <script setup> import { onMounted } from 'vue' function createElement (el, url, type) { const script = document.createElement(el) if (type ...

JavaScript function occasionally experiences loading issues with CSS images

Have you ever encountered issues with a CSS background image failing to load? What might be the underlying cause? I've written some Javascript code that looks like this: function progressBar(file_id) { pbar = ($("<div />").attr('id&a ...

Utilizing Vuetify's datatable search property in conjunction with an autocomplete component

Currently, I am in the process of setting up a dropdown filter for each column within my Vuetify data table. It appears that the Vuetify autocomplete component offers the functionality I need, but I'm uncertain about how to utilize the values from the ...

Packaging Vue with Gradle into Spark for seamless integration

I am integrating a Vue UI with a backend developed in Spark Java. Both components are created independently and successfully integrated using the following structure: project +-- backend | +-- src | | +-- main | | +-- resources ...

Bizarre Drop-down Peculiarities

Having a perplexing issue where the 'search' list item is oddly shifted below the dropdown box only when it is displayed. The other list items remain in their correct positions. Any advice on how to resolve this? The appearance and functionality ...