Search code examples
vue-resourcevuejs2

Set value to a property on GET request


Trying to update a value of vue property based on server response:

  @registration = new Vue(
    el: '#calculator_calendar'
    data:
      constraints:
        amount:
          min: null
          max: null

and method where I do GET request

 loadConstraints: () ->
    @$http.get(constraintsUrl).then ((response) ->
      @$set 'constraints.amount.min', response.data.constraints.amount.min

what is the correct syntax to update constraints.amount,min.

With older versions used to do

@$set 'constraints.amount.min', response.data.constraints.amount.max

but it doesn't work anymore, fails with

Uncaught (in promise) TypeError: Cannot create property '100' on string 'constraints.amount.min'

versions:

  • Vue v2.0.8
  • vue-resource v1.0.3

Solution

  • You can just assign it, like it is done in javascript:

     loadConstraints: () => {
        var vm = this
        $http.get(constraintsUrl).then ((response) =>
          vm.constraints.amount.min' = response.data.constraints.amount.min