# Vue (/vela-pro/get-started/frameworks/vue)



Vela's open-source core and Vela Pro mount directly into a template element in Vue 3. In `<script setup lang="ts">`, construct `VelaWorkspace` inside `onMounted`, store the workspace in a plain `let` variable rather than `ref()`, watch props to update the chart in place, and call `workspace.destroy()` in `onBeforeUnmount`.

## Single-File Component [#single-file-component]

```vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { VelaWorkspace } from '@luxalgo/vela/workspace';
import { BinanceProvider } from '@luxalgo/vela/providers/binance';
import { enableVelaPro } from '@luxalgo/vela-pro';

const props = withDefaults(defineProps<{ symbol?: string }>(), {
    symbol: 'BTCUSDT',
});

enableVelaPro();

const container = ref<HTMLDivElement | null>(null);
let workspace: VelaWorkspace | undefined;

onMounted(() => {
    workspace = new VelaWorkspace(container.value!, {
        layout: false,
        symbol: props.symbol,
        timeframe: '60',
        live: true,
        providers: { binance: () => new BinanceProvider() },
    });
});

watch(
    () => props.symbol,
    (nextSymbol) => {
        if (workspace && workspace.active.symbol !== nextSymbol) {
            workspace.active.setSymbol(nextSymbol);
        }
    },
);

onBeforeUnmount(() => {
    workspace?.destroy();
    workspace = undefined;
});
</script>

<template>
    <div ref="container" style="width: 100%; height: 100%"></div>
</template>
```

## Implementation notes [#implementation-notes]

* **Store `VelaWorkspace` in a plain `let` variable**: Do not wrap `VelaWorkspace` in `ref()` or `reactive()`. `VelaWorkspace` is an imperative class instance managing DOM nodes, WebGL2 contexts, and Web Workers rather than reactive template state, and Vue's deep `Proxy` wrapping interferes with internal object identity and adds tracking overhead. If you expose the workspace through `defineExpose`, use `shallowRef` or a getter function.
* **Sync reactive props with `watch()`**: Instantiate `VelaWorkspace` once in `onMounted` and apply subsequent `symbol`, `timeframe`, or `theme` changes via `watch()` so user drawings, active indicators, and open panels remain intact.
* **Calling `enableVelaPro()` in `<script setup>`**: Code inside `<script setup>` runs each time a component instance initializes. Because `enableVelaPro()` is idempotent after the first call, calling it in `<script setup>` (or once in `main.ts`) is safe as long as it runs before `new VelaWorkspace()`.
* **Clean up on unmount**: Calling `workspace?.destroy()` in `onBeforeUnmount` flushes pending state changes, terminates workers and live subscriptions, and removes the workspace DOM from `container`. Give the parent element a non-zero height so the `100%` container has space to fill.

## Verified environment [#verified-environment]

| Stack      | Verified versions | Checks run                                                      |
| ---------- | ----------------- | --------------------------------------------------------------- |
| Vue + Vite | Vue 3.5, Vite 8.3 | Typechecking with `vue-tsc` and production build (`vite build`) |

## Related [#related]

* [Installation](/vela-pro/get-started/setup)
* [Quickstart](/vela-pro/get-started/quickstart)
* [React](/vela-pro/get-started/frameworks/react)
* [Next.js](/vela-pro/get-started/frameworks/nextjs)
* [Events and subscriptions](/vela-pro/charts/events)
