vue-router-parameters (get and post mode)

This paper describes two ways to pass parameters vue-router:
1, get way
Jump pages
. This $ router.push ({path: '/ xxx', query: {id: 1}}); // get a similar parameter passing, passing parameters through the URL
New page receives parameters
this.$route.query.id
 
2, post way
Jump pages
 // Because of the dynamic routing is passed params, so the path can not be used together and params in this. $ Router.push () method, otherwise it will be invalid params.
You need to use the name to the specified page.
. this $ router.push ({name: 'page2', params: {id: 1}}); // post similar parameter passing
 
New page receives parameters
this.$route.params.id
 
3. Note: when the page is refreshed frequently encountered parameters have changed, but the new page to accept the argument has not changed. This problem can be solved by adding watch.
Watch: {
       '$ route ' (to, from) { 
        // here again refresh this.getParams ();  }  }
        

Guess you like

Origin www.cnblogs.com/liufeiran/p/11698033.html