vue-带有参数的路由跳转

首页-详情页-列表页


selectItem(item){
        this.$router.push({
       path: '/guessdetail', query:{shopid: item.id}
        });  

   }

created(){
    this.fetchData()
    },
    watch: {
      // 如果路由有变化,会再次执行该方法
     '$route': 'fetchData'
     },

methods:{
//获取店铺信息
fetchData () {
this.shopid=this.$route.query.shopid;
//因为实时监听路由的变化执行该方法 当没有传入时console会报错  解决方法是没有传入参数时 给设置默认参数
if(this.$route.query.shopid==undefined){
this.shopid=1;
}
this.shopid=parseInt(this.shopid);

猜你喜欢

转载自blog.csdn.net/lsy__lsy/article/details/80091747