admin 管理员组文章数量: 1086019
I'm trying to let players join a game via QR Code. Since that game will be hosted on several IP's, i want to dynamically generate the URL.
This is my current workaround in my NuxtJS Vue Component:
<template>
<input placeholder="copy browser window url into this field" v-model="fullPath" @change="generateQR">
</template>
<script setup>
const fullPath = ref(null)
QRCode.toDataURL(fullPath.value + ...
</script>
What I want to do is something like:
<script setup>
// not working phantasy code
QRCode.toDataURL(window.location.href + ...
</script>
When using useRouter() and useRoute()'s .fullPath
attribute, I still only get the relative path /
instead of :3000/
.
Full code on GitLab: pages/index.vue
I'm trying to let players join a game via QR Code. Since that game will be hosted on several IP's, i want to dynamically generate the URL.
This is my current workaround in my NuxtJS Vue Component:
<template>
<input placeholder="copy browser window url into this field" v-model="fullPath" @change="generateQR">
</template>
<script setup>
const fullPath = ref(null)
QRCode.toDataURL(fullPath.value + ...
</script>
What I want to do is something like:
<script setup>
// not working phantasy code
QRCode.toDataURL(window.location.href + ...
</script>
When using useRouter() and useRoute()'s .fullPath
attribute, I still only get the relative path /
instead of http://10.16.1.173:3000/
.
Full code on GitLab: pages/index.vue
Share Improve this question edited Jun 17, 2022 at 17:28 kissu 47k16 gold badges90 silver badges189 bronze badges asked Jun 16, 2022 at 11:14 Dominik ZiDominik Zi 4435 silver badges14 bronze badges3 Answers
Reset to default 5Try to check if you are in client side before accessing to 'window' object, you can use :
if (process.client) {
console.log(window.location.href)
}
Try to use this:
this.$route.query
In Nuxt 3 you can use the posable useRequestURL() to get the current URL on both server and client (may not work if using hybrid rendering):
const url = useRequestURL();
console.log(url.href);
本文标签: javascriptHow can I get windowlocationhref in Nuxtjs V3Stack Overflow
版权声明:本文标题:javascript - How can I get window.location.href in Nuxtjs V3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744040689a2523199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论