deptyped / vue-telegram

Telegram integration for Vue
https://vue-tg.pages.dev
MIT License
118 stars 6 forks source link

Integrate with nuxt 3 #9

Open ZhulinskiiDanil opened 5 months ago

ZhulinskiiDanil commented 5 months ago

Please! Integrate with nuxt 3

This works only if i write this:

<script setup lang="ts">
  useHead({
      script: [
        {
          src: 'https://telegram.org/js/telegram-web-app.js',
          defer: true
        }
      ]
    })

  onMounted(async () => {
    const VueTg = await import('vue-tg')
  })
<script>

If i write import without onMounted, nuxt throws error "Telegram is not defined"

because nuxt first render in server side

deptyped commented 5 months ago

Hello. Telegram Mini App API exists only in Telegram app, so we can't render it on server side. How do you expect it to work?

ZhulinskiiDanil commented 5 months ago

Hello. Telegram Mini App API exists only in Telegram app, so we can't render it on server side. How do you expect it to work?

As an option on the server, avoid the error and return null so that you don’t have to write constructs using onMounted

deptyped commented 5 months ago

Unfortunately, I don't have enough experience with nuxt and not sure how to implement it properly. PRs are welcome!