vue3 路由跳转新页面并传递参数与获取参数

admin2024-07-10  39

打开新标签页面传递参数(useRouter )
import { useRouter } from 'vue-router'
const uRouter = useRouter()
let page = uRouter.resolve({
          path:'/mapRollerShutter',
          query:{
            type:'Split',
            key:1
          }
        })
 window.open(page.href,'_blank')
页面接收(useRoute )
import { useRoute } from 'vue-router'
const uRoute = useRoute()

const key = ref()
const source = ref()

onMounted(() => {
key.value = parseInt(uRouter.query.key)
source.value = uRoute.query.type
})

补充:不创建新标签页传参
import { useRouter } from "vue-router"
const uRouter = useRouter()
uRouter .push({
		path:'/mapRollerShutter',
		query:{
			type:'Split',
            key:1
            }
	})
	

parmas的形式传参需在路由处定义

//路由(跟?非必传,没有则必传)
path: "/mapRollerShutter/:type/:key?",

//跳转
import { useRouter } from "vue-router"
const uRouter = useRouter()
uRouter .push({
		path:'/mapRollerShutter',
		params:{
			type:'Split',
            key:1
            }
	})

//接收
import { useRoute } from 'vue-router'
const uRoute = useRoute()
console.log( uRoute.params)
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明原文出处。如若内容造成侵权/违法违规/事实不符,请联系SD编程学习网:675289112@qq.com进行投诉反馈,一经查实,立即删除!