【发布时间】:2016-05-29 05:42:19
【问题描述】:
我正在构建一个简单的 REST API(使用 PouchDB 和 Vue.js)。现在,我可以用几个字段创建projects:
server.js:
var express = require('express')
var PouchDB = require('pouchdb')
var app = express()
var db = new PouchDB('vuedb')
app.post('/projects/new', function(req, res) {
var data = {
'type': 'project',
'title': '',
'content': '',
'createdAt': new Date().toJSON()
}
db.post(data).then(function (result) {
// handle result
})
})
client.js:
// HTML
<input type="text" class="form-control" v-model="title" placeholder="Enter title">
<input type="text" class="form-control" v-model="content" placeholder="Enter content">
<button class="btn btn-default" v-on:click="submit">Submit</button>
// JS
submit () {
this.$http.post('http://localhost:8080/projects/new').then(response => {
// handle response
})
}
如何传递参数来设置title 和content?在 REST API 中执行此操作的传统方法是什么?
【问题讨论】:
-
URL 参数:
http://localhost:8080/projects/new?title=Alien&content=scream... Express 有方法(我认为是req.params)来挑选这些值。
标签: javascript rest express vue.js pouchdb