mercredi 1 mai 2019

Axios one step behind vue's v-model

I've trouble finding out why my method logs the step before the actual one. So If I select 1 in a box and then 2, I'll get printed out nothing then 1.

Here is my code :

<b-form-select @input="setCadeauOrReduction(vGiftCard)" @change="calculateNet(vGiftCard)" v-if="this.cadeauOrReduction != 'reduction'" v-model="vGiftCard" id="bonCadeauSoin">
                                    <option></option>
                                    <option v-for="boncadeau in boncadeaus" :key="boncadeau.id" v-bind:value="boncadeau.id">
                                        <p>N° </p>
                                        
                                        <p>|</p>
                                        
                                        <p>CHF</p>
                                    </option>
                                </b-form-select>

This basically calls the function @change. It gives me the Gift card's id as parameter. Then the function it calls :

fetchOneBonCadeau(idToFetch)
        {
            axios.get('/bonCadeaus/' + idToFetch)
            .then((res) => { 
                this.bonCadeauPourAxios = res.data
            })
            .catch((err) => {
                console.log(err);
            })

            return this.bonCadeauPourAxios;
        },

        //Calculer montant net
        calculateNet(value)
        {
            console.log(this.fetchOneBonCadeau(value));


            if(this.vReasonReduction)
            {   
                this.vCostNet = this.vCostBrut - this.vCostBrut * this.vReasonReduction.reductionAmount;
            }
            else
            {
                this.vCostNet = this.vCostBrut;
            }
        }

The console.log part always lags one step behind. I can't figure why. This is my controller if needed :

public function show($id)
{

    $bonCadeau = BonCadeau::where('id', $id)->first();

    return $bonCadeau;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire