onMounted(async () => {
// 获取当前页面的 URL
var currentURL = window.location.href
// 创建 URL 对象
var url = new URL(currentURL)
// 提取主机地址
baseAddress.value = url.origin
init()
})
获取地址中的参数
// 方式一 地址传参
import { useRouter, useRoute } from 'vue-router'
const route = useRoute()
const router = useRouter()
console.log('route.query', route.query)
// 方式二
// hashIndex + 8 8代表的是 #/login? dataString 就是参数信息
onMounted(() => {
const url = window.location.href
if (url.includes('?orgOwnerName')) {
const hashIndex = url.indexOf('#/login?')
const dataString = url.substring(hashIndex + 8)
const params = new URLSearchParams(dataString)
const obj = {}
for (const [key, value] of params.entries()) {
obj[key] = value
}
console.log('obj:', obj)
handleSetToken(obj)
}
})