2

我有以下内容:

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);
});
4

2 回答 2

5

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

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);
});
于 2016-02-18T22:49:42.290 回答
1

在数据对象中创建对象

new vue({
 el:'#point'
data: {

newdata:{
token:'',
bidAmount:''
 }
}

});

现在你可以

this.$http.post('/place-bet',this.newdata, function(response) {
    alert(response);
});
于 2016-02-19T08:01:47.810 回答