Experiencing difficulties with the Vue Template regarding the CSS Modules `$style` object

Utilizing CSS Modules in my Vue application introduces a challenge when trying to render dynamic classes within a particular section of the template. The issue lies in rendering the class from the $style object.

Within my internal data, I have toggles for boolean values:

data() {
  return {
    upper: false,
    lower: false,
  };
},

In the template snippet below, I am attempting to implement this:

<div
  :class="[$style['class 1'], activeClass]">
</div>

The 'activeClass' is computed as follows:

activeClass() {
  return this.$style['active-class'] = this.upper;
}

There are methods that handle 'upper' and 'lower' based on certain logic. While these internal data values do produce the expected results, dynamically adding the 'activeClass' in the template seems to be an obstacle.

Answer №1

<script>
export default {
  highlightActiveClass() {
    console.log($style['active-class']);
    return this.$style['active-class'] = this.upper;
    // -> "blue_9KlpH-cB"
    // a unique identifier created using the filename and class name.
  }
}
</script>

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

What is the process of transforming an Angular object that includes nested child objects and arrays?

I'm currently working on an Angular project and I am looking for a way to extract and modify the formData before sending it to the server as JSON. Here is the original data: { "BioData":{ "firstname": "Greg", " ...

Is there a way to send a variable to the alert function using $.ajax()?

I need assistance with confirming the deletion of a record. When the user clicks on the button, it should send the value 'Yes' to a $_POST request in PHP for deleting the record. However, instead of working as expected, it is showing me the JavaS ...

How to deselect a radio button in AngularJS

I have explored various solutions using ng-dblclick, $event, etc, but none of them seem to work for me. Within a table, I have two radio buttons inside an ng-repeat. I have a field that determines which radio button should be active. While using ng-change ...

How can I align two inner boxes vertically in the most efficient manner?

.dd{ height:100px; width:100%; border:1px soild red; background:#000; } .dd .d1{ height:20px; width:20px; border:1px solid green; display:inline-block; } .dd .d2{ height:20px; width:20px; border:1px solid green; display:inl ...

What is the best way to have an HTML radio button automatically display as selected upon loading if the stored value is "on"?

Utilizing Javascript alongside html: I am facing an issue where a list containing radio buttons is dynamically loaded based on stored data when the page launches. Despite the stored value of the radio being set to "on", the radio button does not show up a ...

Leverage the power of getServerSideProps when working with Dynamic Routes

I have been working on implementing getServerSideProps in my file named [username].js which utilizes dynamic routing. Next.js requires the use of both getStaticPaths() and getStaticProps({ params }) for dynamic routing. However, there seems to be an issu ...

Selecting an unconventional background image for div

I am working on an ASP.NET website that displays products from a database. Currently, the background image for each product is set in CSS within the productBox class. I would like to have a random background image out of a selection of 4 images for each ...

What is the best way to configure my card components for a flex display?

Currently, I am in the process of learning React. I have a file named new_card_component.js that is responsible for displaying data fetched from the data.js file. The issue arises in my AirBnB.js file, where I'm passing the AirbnbApp module to a secti ...

Is the Angular ng-init causing issues with updating the model in the $scope function?

I am currently developing a test web application. The primary functionalities at the moment are user login and posting messages. When the user clicks a button, the following code is triggered: $scope.getData = function(){ $http.get('/messages&ap ...

Sorting Tables - My goal is to ensure that when sorting parent rows, the child rows are also correctly moved along with them

Can I sort parent rows and move child rows along with them using JavaScript? Here is an example of my table structure: <table> <tr class="parent"> <th id="apple">Apple</th> <th id="orange">Orange</th> ...

"Encountering critical issues while executing gulp in the terminal

https://i.sstatic.net/gobwG.png When running the gulp command, I keep encountering these errors. What could be causing this issue? SyntaxError: Unexpected token : at exports.runInThisContext (vm.js:54:16) at Module._compile (module.js:375:25) at Ob ...

Obtaining the name of a category based on its ID in the ParkingArea table using Laravel

Hello everyone, I need some help! I currently have two tables in my database - one for categories and another for parking areas. My goal is to display the name of the category when listing the parking areas. In my ParkingArea model, I've set up a rel ...

verifying the user's screen dimensions

I'm currently exploring ways to customize the appearance of my website based on the viewer's screen resolution. I am interested in potentially optimizing the layout for vertical screens on mobile devices, and horizontal screens for laptops. Addit ...

Step by step guide on including a JavaScript function in a web worker using importScripts

I am encountering an issue with my worker.js file: self.importScripts('/static/utils/utils.js') onmessage = (e) => { let a = e.data[0] let b = e.data[1] let c = func1(a,b) postMessage(c) } The structure of the utils.js file ...

There seems to be an issue with locating the module '/opt/repo/ROOT/server.js'

Error in server.js on jelastic node.log file When attempting to publish a simple page created with Bootstrap using nodejs express and ejs, the server is returning a 504 Gateway timeout error and the application cannot run. The node.js log file is displayi ...

Interactive horizontal web design with center alignment and dynamic scrolling feature

We have designed a unique web layout that is centered horizontally and includes an animated scrolling effect. There are 5 menu options that use simple anchor links to navigate between different pages. Our layout features static content with only the body s ...

Numerous buttons available for inputting into individual text boxes all on one page

<html> <body> <script> function enterNumber(num) { var txt=document.getElementById("output").value; txt=txt + num; document.getElementById("output").value=txt; } </script> Select numbers: <br> <input type="button" val ...

Making a surface-level copy of an array containing nested arrays

I am facing an issue with manipulating child arrays within a parent array. Specifically, I want to manipulate the first element in the first child array without affecting the rest of the arrays. However, my current code is shifting the first elements of al ...

Modifying characters within a designated class definition

I'm working on integrating Isotope with a CuteNews system, and in order to make the filtering function properly, I need to include some identifiers in my class declaration for each isotope item. Link to Isotope In CuteNews, my news items can have mul ...

Modifying the status of a link using jQuery

My ajax function handles two different outcomes based on the class of the link that is clicked. To avoid reloading the entire page when the link is clicked, I have utilized the following code: Everything seems to be working fine, however jQuery still rec ...