[Vuejs]-Bootstrap Vue Progress Bar cannot get its value from function

0👍

Are you sure you’re in the right range?

Perhaps your values range from [0,100] and the expected value ranges [0.0,1.0].

0👍

Okay, I got it fixed by changing the computed to the following:

    computed: {
    getOverallScore: function () {
        var i;
        var sum = 0;

        // Will get all reviews through API calls
        for (i = 0; i < this.items.length; i++) {
            sum = sum + this.items[i].score;
        }

        this.average = Number.parseFloat(sum / this.items.length).toFixed(2);

        return Number.parseFloat(sum / this.items.length);
    },


}

Apparently when I use .toFixed(2), the b-progress no longer recognises the value as a number but as a string. I tried to convert it using Number(this.average) and return that still does not work. I found this very strange though, as the toFixed function is part of the built in library and somehow it does not recognise it as a function. The output value is fine so the toFixed function works. No idea why it does that.

Leave a comment