this.$router.push(location)不行的原因之一

发布于:2022-12-08 ⋅ 阅读:(260) ⋅ 点赞:(0)

 goSearch(event){

        // this.$router.push('/search')

        let element = event.target

        let {categoryname,category1id,category2id,category3id} = element.dataset

        // 如果标签上有categoryname一定是a标签

        if(categoryname){

            //整理路由跳转的参数

            let loction = {name:'search'};

            let query = {categoryName:categoryname}

            // 一级分类二级分类三级分类的a标签

            if(category1id){

             query.category1Id= category1id

            }else if(category2id){

             query.category2Id= category2id

            }else {

             query.category3Id= category3id

            }

            // 判断路由跳转的时候,带有params参数。捎带传过去

            if (this.$route.params) {

             loction.params = this.$route.params

                // 整理完参数(对象赋值)

            loction.query = query

            // 路由跳转

            this.$router.push(loction)

            }

        }

    },

  

 methods: {

    AddSearch(){

        // 路由传参

       if (this.$route.query) {

        let loction =  { name:"search",params:{keyword:this.password || undefined} }

         loction.query = this.$route.query

         this.$router.push(loction)

       }

    }

  }

解决 路由配置name

  {

            path: '/home',

            name:'home',

            component: Home,

            // 路由元信息 作为footer显示隐藏的判段条件频繁操作用v-show

            meta: { requiresAuth: true }

        }