Vue路由传参params与query的区别和 vue 使用resolve打开浏览器新窗口跳转

1.params使用方式

路由跳转

this.$router.push({
    
    path:'/myMessage',params:{
    
    name:'答案'}})

获取参数

 const params= this.$route.params

2.query的使用方式

路由跳转

 this.$router.push({
    
    path:'/myMessage',query:{
    
    name:'答案'}})

获取参数

 const query = this.$route.query

区别:
1.使用query进行传参,参数将会携带在浏览器url地址栏中,且页面刷新后仍可以获取到参数
2.使用params进行传参,参数不携带在浏览器url地址栏中,且页面刷新后获取不到参数

3.使用 resolve 打开浏览器新窗口

打开新窗口跳转

const {
    
     href } = this.$router.resolve({
    
     path:'/myMessage' })
window.open(href, '_blank')

带有参数的跳转

const {
    
     href } = this.$router.resolve({
    
     path:'/myMessage' ,query:{
    
    name:'答案'}})
window.open(href, '_blank')

猜你喜欢

转载自blog.csdn.net/weixin_43835425/article/details/105346521
今日推荐