如何在使用vuejs时在url中传递多个参数

时间:2017-08-28 08:26:28

标签: parameters vue.js

嘿,我试图在我的网址中为一个简单的水疗中心传递两个参数,并使用api从网址中提取参数值并传递给服务器,这里是网址:

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));

})

1 个答案:

答案 0 :(得分:2)

您的获取请求应为

this.$http.get('/api/game/'+this.$route.params.name + '/' + this.$route.params.token)

您忘记了'/'