Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass multiple parameters in url when using vuejs

Tags:

Hey i am trying to pass two parameters in my url for a simple spa and the params values will be extracted from the url using an api and passed to the server here is the url:

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

but when i am hitting the url its passing this in the network:

Request URL:http://localhost:8080/api/game/usernametoken

and hence it is not hitting the right api

router:

    {path:'game/:name/:token', name:'game', component: game  }

front end:

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

server-side:

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

})
like image 263
Kushagra Agarwal Avatar asked Aug 28 '17 08:08

Kushagra Agarwal


People also ask

How do I pass multiple parameters in URL?

To add a parameter to the URL, add a /#/? to the end, followed by the parameter name, an equal sign (=), and the value of the parameter. You can add multiple parameters by including an ampersand (&) between each one.

How can I get query parameters from a URL in VUE JS?

You can get the query string parameter simply using Vue. js route. In the given URL the key is test and the value is yay .

How do I move data from one page to another in Vue?

Using Props To Share Data From Parent To Child # VueJS props are the simplest way to share data between components. Props are custom attributes that we can give to a component. Then, in our template, we can give those attributes values and — BAM — we're passing data from a parent to a child component!


1 Answers

Your get request should be

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

You forgot the '/'

like image 197
Vamsi Krishna Avatar answered Oct 18 '22 09:10

Vamsi Krishna