路由传参
通常用编程式路由进行传参
首先在router.js路由中进行占位
1 // /:keyword需要先占位 2 { 3 path:'/Search/:keyword', 4 component:Search, 5 name:"Search", 6 meta:{show: true} 7 },
路由传参有三种方式,我们常用第三种对象形式
1 methods:{ 2 goSearch(){ 3 this.$router.push('/Search'); 4 // 编程式路由携带参数,第一种字符串形式 5 // this.$router.push('/Search/'+this.keyword+"?k="+this.keyword.toUpperCase()); 6 // 第二种模板字符串 7 // this.$router.push(`/Search/${this.keyword}?k=${this.keyword.toUpperCase()}`) 8 // 第三种对象传参 需要name 9 this.$router.push({name: "Search",params:{keyword:this.keyword}, query:{k:this.keyword.toUpperCase()}}) 10 // console.log(this.keyword) 11 }, 12 } 13 }