Skip to content

@telegram-apps/sdk-vue

Vue.js package providing utilities that developers may find useful when developing a mini application.

TIP

Since this package offers utility functions that extend the functionality of @telegram-apps/sdk, it is recommended to review the SDK package documentation first.

Installation

Before proceeding, it is assumed that you have already installed the vue package, as it is a peer dependency of this package.

bash
pnpm i @telegram-apps/sdk-vue
bash
npm i @telegram-apps/sdk-vue
bash
yarn add @telegram-apps/sdk-vue

INFO

This package fully re-exports the @telegram-apps/sdk package, so you don't need to install it separately.

Usage

Here is a simple usage example of the package:

tsx
import { createApp } from 'vue';
import { init, backButton } from '@telegram-apps/sdk-vue';

import { BackButton } from './BackButton.vue';

// Initialize the package.
init();

const app = createApp(BackButton);

// Mount the Back Button, so we will work with 
// the actual component properties.
backButton.mount();

app.mount('#root');
vue
/**
 * Component which controls the Back Button visibility.
 */
<script setup lang="ts">
import { watchEffect, onMounted, onUnmounted } from 'vue';
import { backButton, useSignal } from '@telegram-apps/sdk-vue';

const isVisible = useSignal(backButton.isVisible);

watchEffect(() => {
  console.log('The button is', isVisible.value ? 'visible' : 'invisible');
});

onMounted(() => {
  backButton.show();
});

onUnmounted(() => {
  backButton.hide();
});
</script>

<template></template>

Hooks

useSignal

A helper that allows you to use our signals in the application. It returns a Vue ref which updates every time, our signal changes.

vue
<script setup lang="ts">
import { watchEffect, onMounted, onUnmounted } from 'vue';
import { backButton, useSignal } from '@telegram-apps/sdk-vue';

const isVisible = useSignal(backButton.isVisible);

watchEffect(() => {
  console.log('The button is', isVisible.value ? 'visible' : 'invisible');
});

onMounted(() => {
  backButton.show();
});

onUnmounted(() => {
  backButton.hide();
});
</script>

<template></template>

useLaunchParams

A function that returns the mini application's launch parameters.

vue
<script setup lang="ts">
import { useLaunchParams } from '@telegram-apps/sdk-vue';

const lp = useLaunchParams();
</script>

<template>
  <div>Start param: {{ lp.startParam }}</div>
</template>

Released under the MIT License.