可以使用 Vue.js 内建的 $route 对象来获取 URL 中的參數值。$route.query.family 可以获取到 '?family=abc' 中的 family 参数值,即 'abc'。

示例:

import { createWebHashHistory } from 'vue-router'

const router = createWebHashHistory()

router.beforeEach((to, from, next) => {
  console.log(router.currentRoute.value.query.family) // 获取 family 参数值
  next()
})
Vue Router 使用 createWebHashHistory() 获取 URL 参数 'family' 的值

原文地址: https://www.cveoy.top/t/topic/lCw4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录