如何在URL中传递多个参数时使用vuejs
问题描述:
嘿,我想在我的网址传递两个参数为一个简单的SPA和params值将从URL中使用api提取并传递到服务器这里的URL :如何在URL中传递多个参数时使用vuejs
http://localhost:8080/#/game/username/token
,但是当我打它通过这个网络中的URL:
请求URL: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));
})
答
你的GET请求应该是
this.$http.get('/api/game/'+this.$route.params.name + '/' + this.$route.params.token)
你忘了'/'
显示一些代码,请... –
不好意思,我正在编辑和添加代码 –