Vue 3.0之路由传参

在 vue3.0 里面使用路由必须要引入 useRouter 和 useRoute

import { useRoute, useRouter } from 'vue-router'
function useHooks() {
  const Router = useRouter() //跳转
  const Route = useRoute() //获取到值
  const Routeid = computed(() => {
    return Route.query.id
  })
  const gotourl = () => {
    console.log('aaaaa了')
    Router.push({
      path: '/about',
      query: {
        id: 'aaaaaa',
      },
    })
  }
  return {
    gotourl,
    Routeid,
  }
}

 

posted @ 2021-07-16 11:43  糖果_小宝  阅读(1398)  评论(0编辑  收藏  举报