首页 > 解决方案 > 将有效负载添加到 axios 请求

问题描述

我对我的 axios 请求有一些疑问。要从 API 获取信息,我的请求中需要一个密钥和一个秘密 - 在我的示例中这是否正确实施,我在哪里可以找到正确的密钥/秘密?

以及如何向我的 axios 请求添加有效负载以获得对该请求的特定答案?

var my_url = "https://secret.de";

var myResponse = "";

function My(axios) {
  this.axios = axios;
  this.vue = this.getMyResponse();
  this.vue.getData();
}

My.prototype.getMyResponse = function() {
  var myRequest = new Vue({
    headers: {
      "consumerKey": "key",
      "consumerSecret": "secret",
    },
    el: '#widget1',
    method: 'post',
    data: {
      myResponseData: ''
    },
    methods: {
      getData: function () {
        axios.all([
          axios.post(my_url, {
            username: "username",
            password: "password"
          })
        ])
        .then(axios.spread(function (myResponseOne) {
          myWidget(myResponseOne);
          myRequest.$data.myResponseData = myResponse;
        }))
      }
    },
  });

  timeout = setInterval(myRequest.getData, 60000);
  return myRequest;
};

谢谢!

标签: javascriptrestrequestaxios

解决方案


推荐阅读