从Vue.JS发布到Express路由器

我试图从一个vue.js前端数据发布到我的express / node后端。 POST似乎通过,但在后端我只是得到一个未定义的空数组。

前端:

main.js

 var app = new Vue({ el: '#app', data: { guests: [], code: '', showGuests: true }, methods: { saveGuests: function() { $.ajax({ type: "POST", url: '/api/rsvp/' + this.code, data: this.guests, success: function() { this.showGuests = false; // do more stuff to handle submission }, dataType: 'json' }); }, ... 

后端:

app.js

 //body parser var bodyParser = require('body-parser') //express var express = require('express'); // cfenv provides access to your Cloud Foundry environment // for more info, see: https://www.npmjs.com/package/cfenv var cfenv = require('cfenv'); // create a new express server var app = express(); var rsvp = cloudant.db.use('rsvp'); // get the app environment from Cloud Foundry var appEnv = cfenv.getAppEnv(); // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: false })) // parse application/json app.use(bodyParser.json()) // serve the files out of ./public as our main files app.use(express.static(__dirname + '/public')); //endpoint to post rsvp details app.post('/api/rsvp/:code', function(req, res) { console.log(req.body); res.send('POST request received successfully') }); // start server on the specified port and binding host app.listen(appEnv.port, '0.0.0.0', function() { // print a message when the server starts listening console.log("server starting on " + appEnv.url); }); 

guests数组由另一个我省略的函数填充。 它看起来像这样:

 [{ fullName: "john smith", rsvpStatus: "Not Responded" },{ fullName: "Mr Stack Overflow", rsvpStatus: "Yes" }] 

节点服务器上的console.log只是在POST尝试后给我的:

 { undefined: [ '', '' ] } 

任何帮助将是伟大的。 也许在我发布之前,我需要用Vue数据绑定来做些什么? 我是Vue的新手,所以几乎可以肯定地做错了什么。

感谢:D

自己pipe理回答。 基本上由于某些原因,在Vue中使用jQuery POST会搞砸了一些东西。 我为vue添加了“vue-resource”插件 ,然后可以使用以下方法执行相同的POST:

 this.$http.post('url', data);