Vue calculation properties cannot be calculated in real time

 computed:{
            //- 2018-12-31
            aftershopticket_total:function(){

                // 

                var x;
                var t=0;
                for(x in this.shopcart_shop){
                    t+=parseFloat(this.afterdiscount_shoptotal(x));
                }

                return t.toFixed(2);

            },
        },

this.afterdiscount_shoptotal (x) data has changed, but the entire calculation property is still not re-executed
is the same in calculation properties and methods. How should it be handled to calculate in real time

Mar.24,2022

I have encountered this problem before. The reason for this problem is that vue cannot listen to dynamically adding properties to an object in Vue. For example, just like here, the shopcart_shop object starts out as an empty object ({}), and then you pass the event. this.shopcart_shop.addkey = 1 , although the object becomes {addkey: 1}, vue cannot be monitored accordingly. So there are two ways to solve it.
the first way is to add the addkey attribute to the data where you define the shopcart_shop object. For example:

this.shopcart_shop watch

watch:{
    shopcart_shop:{
        handler(newval,oldVal){
            this.afterdiscount_shoptotal
        },
        deep:true
    }
}
Menu