嘿,我正在尝试为简单的spa在URL中传递两个参数,并且将使用api从URL中提取params值并将其传递给服务器,这里是URL:
http:// localhost:8080 /#/ game / username / token
但是当我点击网址时,它会在网络中传递:
请求网址:http:// localhost:8080 / api / game / usernametoken
因此它没有达到正确的api
路由器:
{path:'game/:name/:token', name:'game', component: game }
前端:
this.$http.get('/api/game/'+this.$route.params.name+this.$route.params.token)
服务器端:
app.get('/api/game/:name/:token',function(req,res,err){
var tex = {push:false};
console.log("diplaying token from the server"+req.params.name+req.params.token)
res.end(JSON.stringify(tex));
})
您的获取请求应为
this.$http.get('/api/game/'+this.$route.params.name + '/' + this.$route.params.token)
你忘了 '/'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句