Помогите переписать REST запрос с jquery на vue-resource

250
12 апреля 2017, 15:07

Есть такой кусок кода на jquery с постом на сервер:

      //Build the command string that will be passed to the spark core's
      //setRgb function.  The command will be in the format of "r,g,b"
      var command = localRed + ',' + localGrn + ',' + localBlu;
      //Create the url for the spark core's setRgb function with the
      //required coreId value.
      var url = "https://api.spark.io/v1/devices/" + coreId + "/setRgb";
      //Show the ajax_loader div to indicate that the post has begun
      //the div overlays the slider controls and prevents the sliders
      //from being changed while the update is in progress. This
      $('#ajax_loader').show();
      //Create a jQuery.ajax request to post the new RGB values to the setRgb function
      $.ajax({
        type: "POST",
        url: url,
        data: {
          access_token: accessToken,
          args: command
        },
      }).then(function () {
        //Then set the posting flag to false so another post can run
        posting = false;
        //hide the ajax_loader div
        $('#ajax_loader').hide();
      });
    };

не могу переписать на https://github.com/pagekit/vue-resource

вот что получается у меня, коннект проходит, access_token вставил в запрос, а вот доп аргументы localRed + ',' + localGrn + ',' + localBlu не могу передать:

this.$http.post('https://api.spark.io/v1/devices/3b0041000747343232363230/setRgb?access_token=ba2b57075f7261d9751ef46c50fe3440d5ef1c8d').then(function(response) {
          console.log("Sucess post")
        },  function(error) {
          console.log("Error post!")
        })
Answer 1
var command = localRed + ',' + localGrn + ',' + localBlu;
var url = 'https://api.spark.io/v1/devices/3b0041000747343232363230/setRgb?access_token=ba2b57075f7261d9751ef46c50fe3440d5ef1c8d';
this.$http.post(url, { args: command }).then(function(response) {
    console.log("Sucess post")
},  function(error) {
    console.log("Error post!")
})
READ ALSO
vue модальное окно ошибка с props

vue модальное окно ошибка с props

Vue компонент модального окнаПри вызове метода savePos

373
Как навесить событие на кнопку?

Как навесить событие на кнопку?

Есть форма с кнопкой,вот код инпута

240
Задача из книги Выразительный Javascript

Задача из книги Выразительный Javascript

Всем приветСейчас осваиваю Javascript через книгу "Выразительный javascript"

318