a页面代码:
<MenuItem :name="item.href" @click.native="changePanel(item.href)">{{item.name}}</MenuItem>
methods:{
changePanel:function(pagehref){
this.$router.push({path: arr[0] , query:param }); // 参数动态
}
}
其中:arr[0] 是路由的path,已经在router/index.js中声明该组件,例如:/home/personalPanel
param 是动态的参数,例如:{page:23}
b页面代码:
computed: {
pageCode() {
let pageCode = this.$route.query.page
return pageCode
}
},
watch: {
pageCode: function () {
this.queryInfo();
},
},
created: function () {
this.queryInfo();
let pageCode = this.$route.query.page;
this.pageCode = pageCode;
},
methods: {
queryInfo();
}
问题:
当点击第一次时,浏览器地址是这样的 http://localhost:8070/#/home/personalPanel , 后面参数并没有带出来,b页面的方法全部都会走,并且this.$route.query.page 报 undefined 。
当再次点击时,浏览器地址显示正常 http://localhost:8070/#/home/personalPanel?page=23,b页面的 created 方法不走,其它方法都会走。this.$route.query.page 正常取到 参数。
上面的代码没有问题。
是源代码里面,调用了2次,第一次不是this.$router.push调用,所有没有察觉。
解决方法: