这是我前台发起的请求测试.
this.$http
.get('http://localhost:3000/api/testGet', {
params: {
name: 'get'
}
})
.then(function (data) {
this.Get = data.body.msg
})
this.$http
.delete('http://localhost:3000/api/testDelete', {
params: {
name: 'delete'
}
})
.then(function (data) {
this.Delete = data.body.msg
})
this.$http
.post('http://localhost:3000/api/testPost', {
name: 'post'
})
.then(function (data) {
this.Post = data.body.msg
})
this.$http
.put('http://localhost:3000/api/testPut', {
name: 'put'
})
.then(function (data) {
this.Put = data.body.msg
})
这是我后台的处理
router.get('/testGet', function (req, res, next) {
res.send({msg: 'get '});
})
router.delete('/testDelete', function (req, res, next) {
res.send({msg: 'delete '});
})
router.post('/testPost', function (req, res, next) {
res.send({msg: 'post '});
})
router.put('/testPut', function(req, res, next) {
res.send({msg: 'put '});
})
我不太明白,是否根据 函数的功能来决定这个方法是属于get,delete,put,post中的哪一种?目前 我后台express只提供api,路由,页面都由前台完成。
Yes, POST, DELETE, PUT, and GET correspond to addition, deletion, modification, and query respectively.
Personal understanding:
For example, if you want to operate test. Then, the route should look like this
/api/test
. The front desk can useget
,post
,put
,delete
, etc. to access this route to complete the business. It should no longer beapi/testGET
orapi/testPost
.