Vue router query object's value problem

In use  $ router.push ()  , if using a query, may be obtained from the corresponding parameter of the query after the jump. If you pass a string of natural no problem, but if you pass other types of data, after the jump is normal, but after the break and then refresh the page again, then the value of the property which will become a query string. E.g:

this.$router.push({ name:'product', query: {canSee: false} });

  After the initial jump, this. Value $ route.query.canSee print is Boolean type. Then refresh, the value becomes the String type. Personal guess is because the value of the query refresh is taken directly from the page URL, and type of parameters in the URL of the page can only be a string type.

Solution :

  1. Prior to the traditional values ​​of parameter passed into a single object, which is performed the JSON.parse () into the query processing inside, then the JSON.stringify () process, and then to the target page, to restore the object. The benefit of this approach is that can handle more than one time parameters, and apply high, it is recommended to use this method.

  2. pass before values ​​without processing to the target page of the original data after the individual is a non-string the JSON.parse () process. The disadvantage is that the string type of data processing can not be so, to ensure that the data is not a string type. Limitations, it is not recommended apply.

 

Related articles: Router routing Jump to transfer data using query parameters can not be obtained after refresh

Guess you like

Origin www.cnblogs.com/mengyouyouyou/p/11015135.html