You may have an infinite update loop in a component render function

后端 未结 3 603
野趣味
野趣味 2020-12-29 02:09

I\'m new to VueJS, I\'ve got warning from Vue,

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

When i us

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 02:18

    @Decade is right about the problem. Here is the exact problem:

    1. You are in render method rendering the list of item using some state value

    NOTE: render method is triggered whenever any state changes

    1. Then you are trying to bind the class based on a result of function test this function is flawed as it is again trying to mutate the state, thus causing the render - test - render cycle.

    You can solve this problem by making your test function not mutate the state instead, like so:

    methods: {
        test(result) {
            let accept;
            if (result == 'accept') {
                accept = true;
            } else if (result == 'Not accept') {
                accept = false;
            } else {
                console.log(result);
            }
    
            return {
                success: accept,
                danger: !accept,
            };
        },
    }
    

    I hope that helped!

提交回复
热议问题