1 methods: { 2 //搜索按钮的回调 3 goSearch() { 4 //路由的跳转,采用的是编程式导航. 5 //路由传递参数 6 7 //第一种传递query参数 8 // this.$router.push({path:'/search',query:{keyword:this.keyword}}); 9 10 //第二种传递params参数 [一定要注意,面试的时候经常问] 11 // this.$router.push({name:'search',params:{keyword:this.keyword}}) 12 13 //第三种传递query+params 14 // this.$router.push({ 15 // name: "search", 16 // params: { keyword: this.keyword }, 17 // query: { keyword: "ABC" }, 18 // }); 19 20 //验证Vue-Router引入Promise技术,最笨的方法,给push传递第二个、第三个参数【回调函数】 21 //下面这种写法:治标不治本!!!! 22 // let result = this.$router.push({name: "search",params: { keyword: this.keyword|| undefined}},()=>{},()=>{}); 23 24 //问题1:push方法,里面this是谁? vueRouter类的实例 25 // this.$router.push({name:'search',params:{keyword:this.keyword}}); 26 //问题2:push方法里面的this是谁?windows 27 // let result = this.$router.push; 28 // result({name:'search',params:{keyword:this.keyword}}) 29 30 //点击搜索按钮之前,如果路径当中有query参数,需要携带给search 31 32 let locations = { 33 name: "search", 34 params: { keyword: this.keyword || undefined }, 35 }; 36 //确定路径当中有query参数 37 if (this.$route.query.categoryName) { 38 locations.query = this.$route.query; 39 } 40 41 this.$router.push(locations); 42 }, 43 //退出登录的按钮的回调 44 logout(){ 45 //派遣action退出登录 46 this.$store.dispatch('logout'); 47 } 48 }, 49 mounted() { 50 //清除关键字 51 this.$bus.$on("clearKeyword", () => { 52 console.log(123); 53 this.keyword = ""; 54 }); 55 }, 56 };
原文地址:http://www.cnblogs.com/hs20011205/p/16820360.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性