【问题标题】:how to pass multiple parameters in url when using vuejs使用vuejs时如何在url中传递多个参数
【发布时间】:2018-02-05 11:17:50
【问题描述】:

嘿,我正在尝试在我的 url 中为一个简单的 spa 传递两个参数,params 值将使用 api 从 url 中提取并传递给服务器,这里是 url:

http://localhost:8080/#/game/username/token

但是当我点击 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));

})

【问题讨论】:

  • 请显示一些代码...
  • 对不起,我正在编辑和添加代码

标签: parameters vue.js


【解决方案1】:

你的获取请求应该是

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

你忘了'/'

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 2015-12-10
    • 2013-11-21
    • 2012-06-12
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多