This commit is contained in:
xds
2025-10-27 16:55:27 +03:00
parent c5baeb8155
commit 99890102ef
2 changed files with 27 additions and 3 deletions

View File

@@ -1,14 +1,37 @@
<script setup lang="ts">
import { onMounted, ref, computed } from "vue"
import { WebApp } from "@grammyjs/web-app"
import router from "@/router"; // если используешь другой SDK, импорт может отличаться
// необязательно делать реактивным, но удобно для шаблона
const tgData = ref(WebApp.initDataUnsafe)
const tgApp = window.Telegram.WebApp
// какие-то удобные вычисления для UI
const userId = computed(() => tgData.value?.user?.id?.toString() ?? "")
const username = computed(() => tgData.value?.user?.username ?? "")
const firstName = computed(() => tgData.value?.user?.first_name ?? "")
onMounted(() => {
// сообщаем Telegram WebApp, что UI готов
WebApp.ready()
// если есть данные пользователя — положим что-то в localStorage
if (tgData.value?.user?.id != null) {
localStorage.setItem("token", tgData.value.user.id.toString())
} else {
localStorage.setItem("token", "123")
}
router.push('/')
})
</script>
<template>
{{tgApp}}
<div class="p-4">
<p>Telegram user id: {{ userId || "—" }}</p>
<p>Username: {{ username || "—" }}</p>
<p>First name: {{ firstName || "—" }}</p>
</div>
</template>
<style scoped>
</style>