Vuejs-销毁路由器查询/ URL并创建新URL(将新查询推送到Vue-Router)

时间:2019-12-28 01:26:40

标签: vue.js url vue-router

这样对破坏路由器查询/ URL有意义吗?

 created() {

//Distructure URL i.e. this.$route.query
//distructure from: http://localhost:8080/16/club/Ranks?gender&bestOnly=Y&daysOld=31&facilityType=50m&newOnly=Y
const {gender,bestOnly,daysOld,facilityType,newOnly} = this.$route.query;
//assign to current instance variables
this.gender=gender;
this.bestOnly=bestOnly;
this.daysOld=daysOld;
this.facilityType = facilityType;
this.newOnly = newOnly;    
this.handleGetRanks();

},

并像这样推送或替换新查询:

methods: {
    handleGetRanks() {
        // add query parameters to url
        // example: http://localhost:8080/16/club/Ranks?gender&bestOnly=Y&daysOld=31&facilityType=50m&newOnly=Y
      this.$router.replace({ query: { gender: this.gender, bestOnly: this.bestOnly, daysOld: this.daysOld, facilityType: this.facilityType, newOnly: this.newOnly } });
      //this.$router.push(redir_path);
....

还是有更好的方法可以做到这一点??

0 个答案:

没有答案
相关问题