javascript - Vue.js mounted function runs too early -
essentially trying run a function adds different variables , sets new 1 pretty simple:
addup: function () { this.homescore1 = this.m1g1h + this.m1g2h + this.m1g3h + this.m1g4h + this.m2g1h + this.m2g2h + this.m2g3h + this.m2g4h; this.awayscore1 = this.m1g1a + this.m1g2a + this.m1g3a + this.m1g4a + this.m2g1a + this.m2g2a + this.m2g3a + this.m2g4a; this.homescore2 = this.m3g1h + this.m3g2h + this.m3g3h + this.m3g4h + this.m4g1h + this.m4g2h + this.m4g3h + this.m4g4h; this.awayscore2 = this.m3g1a + this.m3g2a + this.m3g3a + this.m3g4a + this.m4g1a + this.m4g2a + this.m4g3a + this.m4g4a; this.hdoubles = this.m5g1h + this.m5g2h + this.m5g3h + this.m5g4h; this.adoubles = this.m5g1a + this.m5g2a + this.m5g3a + this.m5g4a; alert(this.m1g1h); //total handicap set here this.hhandicap = this.singleshhandicap + this.doubleshhandicap; this.ahandicap = this.singlesahandicap + this.doublesahandicap; //total score calculated here this.homescore = this.homescore1 + this.homescore2 + this.hdoubles + this.hhandicap; this.awayscore = this.awayscore1 + this.awayscore2 + this.adoubles +this.ahandicap; },
the value of this.m1g1h example set in function called this.updatessinglesscores(); run on page creation, calls databse , assignes values returned vue variables:
created: function () { this.updatessinglesscores(); this.updatedoublesscores(); },
afterwards call addup function on mounted:
mounted: function () { this.addup(); }
so problem having variable this.homescore1 example, being displayed in html of page not chnages remains 0. upon further inspection alert in addup function learned this.m1g1h remains 0, though should value. furthermore if run addup function button works fine. 1 explain me why this.m1g1h remains 0? why addup function work when called button?
Comments
Post a Comment