[Vuejs]-Vue js, cant pass data

0👍

calcResult() {

    var deposit_id = $("#deposit_id").val();
    var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;

    this.$http.get(url, function(response){
         return this.calcResult = response;
    });

}

add .bind(this)

 calcResult() {

    var deposit_id = $("#deposit_id").val();
    var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;

    this.$http.get(url, function(response){
        return this.calcResult = response;

    }.bind(this));

}

Or use fat arrow notation since you’re using ES6 syntax

 calcResult() {

    var deposit_id = $("#deposit_id").val();
    var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;

    this.$http.get(url, response => {
    return this.calcResult = response;

    });

}

the this in the .then callback is not the same context as the one outside or within your vue method

Leave a comment