What could be causing the getComputedStyle() method to malfunction within my Nuxt application?

In my Nuxt app, I am working with SSR mode and Vuex. On one of the pages, I have a two-column layout where the text content comes from Vuex data. Here is the code snippet for that page:

<template>
    <div>
        <v-container>
            <v-row no-gutters>
                <v-col cols = "12" md="7">
                    <v-sheet>
                        <v-card class="topCard mt-12">
                            <h1 class="headTitle pb-6 px-12">
                                {{ this.title1 }}
                            </h1>
                            <h2 class="headTitle pb-6 px-12">
                                {{ this.subtitle1 }}
                            </h2>

                            <p class="px-12 py-6 paraCard">
                                <span>Tags: </span>
                                <span class="tagSpan mx-2 px-4" v-for="item in finalTags" :key="item">
                                    {{ item }}
                                </span>
                            </p>

                            <p class="paraCard pt-2">
                                Author:
                                <v-chip
                                outlined
                                large
                                class="pa-5 mr-4"
                                color="var(--color3)"
                                >
                                    {{ this.author1 }}
                                </v-chip> 
                            </p>
                            
                        </v-card>
                    </v-sheet>
                </v-col>

                <v-col cols = "12" md="5">
                    <v-sheet>
                        <v-card class="topCard mt-12">
                            <v-img
                            transition="scale-transition"
                            v-show="show"
                            max-width="250"
                            :src="require(`~/assets/imgs/books/${this.idPage}.webp`)"
                            >
                            </v-img>
                        </card>
                    </sheet>
                    
                </col>
            </row>

            <row no-gutters class="my-16">
                <col cols = "12" md="7">
                    <div class="tozihClass">
                        <div>
                            <h1 class="text-center pa-5">Book Introduction {{ this.title1 }}</h1>
                            <p class="pa-4">
                                {{ this.kamelTozih1 }}
                            </p>
                        </div>
                    </div>
                </col>

                <col cols = "12" md="5">
                    <div class="tozihClass">
                        <div>
                            <h1 class="text-center pa-5">
                                Important Book Titles
                            </h1>
                            <ul class="px-12">
                                <li :key="item" v-for="item in titleSet">
                                    {{ item }}
                                </li>
                            </ul>
                        </div>
                    </div>
                </col>
            </row>
        </container>
    </div>
</template>

<script>

export default {
    data() {
        return {
            allBooks: [],
            allTags: [],
            finalTags: [],
            idPage: 3,
            title1: "",
            author1: "",
            subtitle1: "",
            kamelTozih1: "",
            titleSet: [],
            show: false
        }   
    },
    methods: {
        findData: function(inputArr) {
            this.title1 = inputArr.find(x => x.id == this.idPage).title;
            this.author1 = inputArr.find(x => x.id == this.idPage).author;
            this.kamelTozih1 = inputArr.find(x => x.id == this.idPage).kamelTozih;
            this.subtitle1 = inputArr.find(x => x.id == this.idPage).tozih;
            this.titleSet = inputArr.find(x => x.id == this.idPage).titleList;
            
            let tagIds = inputArr.find(x => x.id == this.idPage).tags;
            this.findTags(tagIds);
        },

        findTags(inputTags) {
            let arrInit = [];
            inputTags.forEach(element => {
                arrInit.push( this.allTags.find(x => x.id == element).name );
            });
            this.finalTags = arrInit;
        },

        setHeight() {
            let elem = document.querySelectorAll('.tozihClass');
            let finalHeight = window.getComputedStyle(elem[1]).getPropertyValue("height");
            console.log(finalHeight);
            document.documentElement.style.setProperty("--equHeigth", finalHeight);
            document.body.style.setProperty("--equHeigth", finalHeight);
        }
    },
    mounted() {
        this.allBooks = this.$store.state.books.list;
        this.allTags = this.$store.state.books.tags;
        this.findData(this.allBooks);

        if (document.readyState === "complete") { 
            this.setHeight(); 
        }
        
    
    },
    created() {
        this.show = true;
    }
}
</script>

<style scoped>
/* CSS Styles */
</style>

Answer №1

One reason why the functionality may not persist after a page refresh is due to the absence of the window and document objects on the server side. Prior to utilizing window and document, it is crucial to first determine if you are operating on the client side by referencing this resource.

In this scenario, two solutions come to mind:

  1. Confirm your presence on the client side and encapsulate your actions within the mounted hook using nextTick() to guarantee complete loading. Eliminate any conditions based on the document readyState in order to potentially resolve arising issues.
  2. An alternative approach would be to forego height calculations and utilize CSS for the desired outcome. Apply styling to the row encompassing the columns containing your tozihClass elements with
    display: flex; align-items: stretch
    . This adjustment should equalize their heights, with potential necessity for setting the column heights to 100%.

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

Getting around CORS using PHP and JavaScript/Ajax

I've been grappling with this issue for hours, but my lack of expertise in web development has me stumped. Here's what I'm struggling with: There is another website that uses a script to fetch information like this: var url = "numbers. ...

Modify the CSS properties of the asp:AutoCompleteExtender using JavaScript

Is there a way to dynamically change the CompletionListItemCssClass attribute of an asp:AutoCompleteExtender using JavaScript every time the index of a combobox is changed? Here is the code snippet: ajaxtoolkit: <asp:AutoCompleteExtender ID="autocom" C ...

Generating Smoke Effects with Three.js

I am looking to generate visually appealing brown smoke rising into the sky. Any tips on how I can achieve this effect? ...

Upgrade personalized AngularJS filter from version 1.2.28 to 1.4.x

When working with a complex JSON response in AngularJS, I encountered the need to filter a deeply nested array within the data. The challenge arose when only displaying a subset of attributes on the screen, leading to the necessity of restricting the filte ...

What is the best way to implement the node.js function into a typical frontend JavaScript file?

I created a node.js puppeteer script to extract data on covid cases in Canada. Now, I want to integrate this function into a frontend website built with JavaScript to display information on Canada's covid cases. How can I export this function to a Jav ...

Is it possible for jQuery to detect if an email was sent from the client's email account?

I am working towards a feature on my website where users fill out specific fields and then click "send email" to activate their email platform via "mailTo", with the email pre-populated for easy sending. The challenge lies in confirming if the user actuall ...

Is there a way to customize the canvas rating animation?

I am looking to implement a rating system, and currently have the following code: Here is my existing code snippet: jQuery.fn.multirating = function() { // Code here } $(function(){ $('.multirating-wrapper').multirating(); }) However, ...

What is the best way to pass $http and $scope using require?

.controller('Ctrlajax', ['$scope', 'version','$sce', '$resource', '$http', function ($scope, version,$sce,$resource,$http) { $scope.answer = 'Waiting for response from the server.....& ...

Implementing React Localized Global Styling

Is there a way to confine the global styles of a module to just one file? For example, I want to adjust the width of an element in a react module but only within one specific file. Unfortunately, inline styles are not an option :/ Edit for clarification: ...

Utilizing Vue to access the Vuex store within a router file

I'm having trouble accessing my store in the router file as shown below. It's giving me undefined when I console.log it. Any suggestions? Currently working with Vue 3. Thanks in advance! import store from '../store/index' const preven ...

Is it possible to turn off ajax within an iframe?

I'm currently developing a project that allows users to customize their page. What is the best way to prevent ajax functionality without having to disable javascript in an iframe? ...

The debate between client-side and server-side video encoding

My knowledge on this topic is quite limited and my Google search didn't provide any clear answers. While reading through this article, the author mentions: In most video workflows, there is usually a transcoding server or serverless cloud function ...

What is the method to transfer a declared object from a .ejs file to my index.js file?

I have a simple script embedded in my .ejs file. The script captures input data from the user and stores it in an object. Now, my goal is to send this object to my index.js file, where I plan to utilize the data with a node module called coap (similar to ...

Using the incorrect file path in Vue Storybook

Recently, I began experimenting with Vue and encountered an issue related to using aliases for importing files in Storybook: In my project, there is a SvgIcon component: <template> <div> props from the icon: {{this.$props}} ...

Track the loading times of individual web pages using JavaScript

Users have been reporting that my existing single-page web application is not performing well, but unfortunately I can't change the code. To address this issue, I want to track the loading time in the following manner: Record the timestamp of when a ...

Upon loading the page, the menu automatically drops down for easy navigation

Currently, I am working on a WordPress site using the WallBase theme. You can check out a preview of the theme here. One issue I am facing is that when the page fully loads, the menu automatically drops down. I have tried various solutions to keep the me ...

Reorganizing Objects in an Array Using NodeJS

Having the following dataset - an array of objects consisting of sender IDs and messages [ { "sender": "1000000000", "message": message 1" }, { "sender": "1000000000&quo ...

Executing functions in a pre-defined order with AngularJS: A step-by-step guide

In my AngularJS Controller, I have a receiver set up like this: // Broadcast Receiver $rootScope.$on('setPlayListEvent', function(event, playListData) { if($scope.someSoundsArePlaying === true) { $scope.stopAllS ...

Interested in utilizing the Google Maps API on your local machine?

Recently, I encountered a problem with my Google Map API while trying to retrieve the nearest places. Here is the code snippet that caused the issue: var headers = { 'Access-Control-Allow-Origin' : '*', 'Content-Type&apo ...

Uploading files with jQuery using Rails and CarrierWave with Amazon S3 storage

I'm relatively new to using jquery file uploading plugins and libraries. Currently, I am working on developing an image uploader that can load images via jquery/ajax on the frontend without requiring a site update as the image is uploaded. Then, I ne ...