【问题标题】:Vue Resource - Post multiple dataVue 资源 - 发布多个数据
【发布时间】:2016-05-31 08:07:03
【问题描述】:

我有以下几点:

bidAmount: {
    amount: 0
},
userToken: {
    token: null
},

this.$http.post('/place-bet', this.bidAmount, function(response) {
    alert(response);
});

如何同时发送this.bidAmountthis.userToken

我试过了,但是它不能正确发送:

this.$http.post('/place-bet', [this.userToken, this.bidAmount], function(response) {
    alert(response);
});

【问题讨论】:

    标签: vue.js vue-resource


    【解决方案1】:

    您应该始终发布一个对象,这样您就可以使用它们各自的键访问服务器上的变量:

    this.$http.post('/place-bet', {userToken: this.userToken, bidAmount: this.bidAmount}, function(response) {
        alert(response);
    });
    

    或者...

    this.$http.post('/place-bet', {data:[this.userToken, this.bidAmount]}, function(response) {
        alert(response);
    });
    

    【讨论】:

      【解决方案2】:

      在数据对象中创建一个对象

      new vue({
       el:'#point'
      data: {
      
      newdata:{
      token:'',
      bidAmount:''
       }
      }
      
      });
      

      现在可以

      this.$http.post('/place-bet',this.newdata, function(response) {
          alert(response);
      });
      

      【讨论】:

        猜你喜欢
        • 2017-01-19
        • 1970-01-01
        • 2018-12-22
        • 2011-01-17
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多