在当前路由中有一个toArticle方法可以跳转到article页面
复制代码
1
2
3
4
5methods:{ toArticle:function(index) { this.$router.push({path:'/article',params:this.blogList[index]}); } }
在article中接受不到params
复制代码
1
2
3
4mounted(){ console.log(this.$route.params) //这里输出undifined }
导致这样的原因是因为params需要通过name来获取,这里就要明白query和params的区别了
query要用path来引入,接收参数都是this.$route.query.name。query类似于ajax中get传参,即在浏览器地址栏中显示参数。
params要用name来引入,接收参数都是this.$route.params.name。params则类似于post,即在浏览器地址栏中不显示参数。
所以以上带面做下面这样的修改就可以获取数据:
复制代码
1
2
3
4
5methods:{ toArticle:function(index) { this.$router.push({name:'article',params:this.blogList[index]}); } }
以上这篇vue router 传参获取不到的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是难过茉莉最近收集整理的关于vue router 传参获取不到的解决方式的全部内容,更多相关vue内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复