Vue application experiencing never-ending update cycle following array assignment

Here is the JavaScript code I am working with:

const storage = new Vue({
    el: '#full-table',
    delimiters: ['[[', ']]'],
    data: {
        events: [],
        counter: 0,
    },

    methods: {
        eventCounter: function() {
            this.counter += 1;
            return this.counter;
        },
        toTime: function(raw_time) {
            console.log(raw_time)
            return moment(raw_time * 1000).format('YYYY-MM-DD HH:mm:ss');
        },
        preprocessData: function(d) {
            if (d["args"]["data"]) {
                d["data"] = d["args"]["data"];
                delete d["args"]["data"];
            }
            return d;
        },

        getData: function(query) {
            let _this = this
            $.get(events_api + 'json?' + query).done(function(new_data) {
                data = new_data.data.map(
                    (item) => _this.preprocessData(item))

                _this.events = data.slice(0, data.length);
                console.log(_this.events)
            }).fail(function(_, _, statusCode) {
                $("#error").html(statusCode);
            });
        },
    },
})
storage.getData('somequery')

This is the corresponding HTML markup:

<div id="full_table">
...
<tbody id="table_data">
<tr v-for="event in events" :key="event.time">
    <td>[[ eventCounter()     ]]</td>
    <td>[[ toTime(event.time) ]]</td>
    <td class="data">[[ event.data || '-' ]]</td>
    <td>[[ event.action || '-' ]]</td>
    <td>[[ event.desc || '-' ]]</td>
    <td>[[ event.args || '-' ]]</td>
</tr>
</tbody>
...
</div>

The issue I am facing is multiple repetitions of console.log(raw_time), displaying FirstTime and SecondTime alternately:

FirstTime
SecondTime
FirstTime
SecondTime
...

Additionally, a warning appears stating:

[Vue warn]: You may have an infinite update loop in a component render function.

I need help on how to prevent this infinite looping behavior after changing the array. Any suggestions?

Answer №1

The issue arose from modifying data within the function call inside a v-for loop in the template - specifically, the eventCounter() function.

I had a dynamic counter variable that was being incremented by 1 on each iteration of the v-for loop. This caused Vue to trigger a rerender of the page after each increment, leading to unexpected behavior.

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 Personalize Navbar in the Bulma Framework

How can I make the <router link> element in my navbar component full width? I'm also looking for keywords related to achieving this layout. Here is an image of the issue: I want a layout that spans the full width, regardless of the Chrome wind ...

"Null" is the value assigned to a JavaScript variable

I am encountering an issue on line 30 with the $.each(data.menu, function (). The console is indicating that "data is null". Can someone clarify what's happening? Thank you! function getFoodMenuData () { var url = 'http://localhost:88 ...

What could be the reason behind the appearance of white lines in my code like this?

Does anyone have an idea why these random lines keep showing up in my code and won't go away unless I restart VScode? My OS is macOS v12.1, but I've been experiencing this issue since version 11 of the software. https://i.stack.imgur.com/lI0Fo. ...

Enhancing web page interactivity through dynamic element names with Javascript and jQuery

I have an interesting HTML setup that looks like this: <div> <input type="text" name="array[a][b][0][foo]" /> <input type="text" name="array[a][b][0][bar]" /> <select name="array[0][a][b][baz]>...</select> </div> ...

Ajax is malfunctioning and failing to fulfill my needs

I cannot get Ajax to submit no matter what. I've been struggling for hours... script: <script> $(document).ready( $("#submit").click(function(e) { e.preventDefault(); $.ajax({ url: "https://maps.googleapis.com/maps/ ...

Develop a Vue mixin to enable theme switching in a Vue.js application

I have successfully developed three distinct themes: light, default, and dark. Currently, I am working on implementing a toggle function in the footer section that allows users to switch between these themes effortlessly. Following the guidance provided b ...

Leverage the NextRouter functionality without the need for a React component

I've created a custom hook that checks if a user is logged in and redirects them to the login page if not. Below is a simplified version of the hook assuming the user is not logged in: import { useRouter } from 'next/router'; export default ...

Integrating JSON with the DOM

Currently, I am searching for a library that offers a simple method to bind JSON data to existing DOM elements that have been generated by a Rails view template. The main reason behind this requirement is that my application features in-place editing (uti ...

Managing HTML5 Video in a slider

I've designed a unique video slider that cycles through 4 videos. Each video has a custom play button and additional overlay content. Once the video starts playing, the overlay content and play button fade out to reveal the default video controls. The ...

arrange a collection within an array containing keys as strings

I am facing an issue with sorting an array of objects. I need to sort the 'list' by 'score' in descending order. var list =[{ '440684023463804938': { score: 6, bonuscount: 2 }, '533932209300832266': { score: 20, b ...

Displaying live data from a spreadsheet directly on a sidebar

My goal is to extract data from another sheet in the same spreadsheet and present it as a dropdown selection in the sidebar. The code.gs file contains a function called getVisualData() that successfully retrieves the desired list: function getVisualData() ...

The scrolling event on the div is not triggering

I'm struggling with this piece of code: const listElm = document.querySelector('#infinite-list'); listElm.addEventListener('scroll', e => { if(listElm.scrollTop + listElm.clientHeight >= listElm.scrollHeight) { th ...

When React object state remains unchanged, the page does not update automatically

i have a state object with checkboxes: const [checkboxarray_final, setCheckboxarray_final] = useState({ 2: ",4,,5,", 9: ",1,", }); i'm working on enabling check/uncheck functionality for multiple checkboxes: these are ...

Addressing the issue of prolonged Electron initialization

Scenario After spending considerable time experimenting with Electron, I have noticed a consistent delay of over 2.5 seconds when rendering a simple html file on the screen. The timeline of events unfolds like this: 60 ms: app ready event is triggered; a ...

Enabling HTTPS as the default for axios HTTP requests

My challenge lies in setting up an ajax request with axios that specifically needs to be made over https. axios.get('/relativeurl') .then((response) => { console.log(response); }) .catch((error) => { console.log ...

The element is implicitly assigned an 'any' type due to the fact that an expression of type 'any' cannot be used to index types in nodejs and solidity

I am in need of setting networks in my contract using NodeJS and TypeScript. Below is the code I have written: let networkId: any = await global.web3.eth.net.getId(); let tetherData = await Tether.networks[networkId]; Unfortunately, I encountered ...

Is there a way in MVC3 / .net4 to convert a JSON formatted JavaScript array into a C# string array?

I am facing a challenge with my MVC3/.Net service where it is receiving arguments in the form of a JSONified Javascript array. I want to convert them into a C# array of strings. Is there a built-in solution available for this task, or do I need to create ...

Incorporating lodash into Angularjs for enhanced functionality

After stumbling upon an app online that utilizes AngularJS with Lodash, I noticed a simple way in which Lodash is incorporated. By including the following line in the body (after angular has been included): <script src='vendor/lodash/3.3.1/lodash. ...

What are some strategies for improving search efficiency in arrays containing over 50,000 elements?

I am working with a large array of strings containing about 50,000 elements. export const companies = [ "000014", "000016", "000017", "000019", "000020", "000021", "000023" ...

Encountering problem with image file encoding while using res.download in Express.js

My node.js server with expressjs is set up for local development, where I store and retrieve various files through basic HTTP calls. Most of the time, everything works smoothly. However, on rare occasions, a small number of files return to the end-user sig ...