Vue Example
This example shows how to use the Code SDK with Vue, Vite, and TypeScript.
First, lets create a new Vue project:
bash
npm create vite@latestnpm create vite@latestSelect Vue and TypeScript when prompted.
INFO
You should be able to run the project with npm run dev and see the default Vue page.
Payment Request
Once you have a Vue project, install the Code elements package:
bash
npm install @code-wallet/elementsnpm install @code-wallet/elementsbash
yarn add @code-wallet/elementsyarn add @code-wallet/elementsbash
pnpm add @code-wallet/elementspnpm add @code-wallet/elementsbash
bun install @code-wallet/elementsbun install @code-wallet/elementsNow, use the onMounted hook to create the button when the container component is mounted.
vue
<script setup lang="ts">
import code from '@code-wallet/elements';
import { onMounted, ref } from 'vue'
const el = ref();
onMounted(() => {
const { button } = code.elements.create('button', {
currency: 'usd',
destination: 'E8otxw1CVX9bfyddKu3ZB3BVLa4VVF9J7CTPdnUwT9jR',
amount: 0.05,
});
button.mount(el.value);
})
</script>
<template>
<div ref="el"></div>
</template><script setup lang="ts">
import code from '@code-wallet/elements';
import { onMounted, ref } from 'vue'
const el = ref();
onMounted(() => {
const { button } = code.elements.create('button', {
currency: 'usd',
destination: 'E8otxw1CVX9bfyddKu3ZB3BVLa4VVF9J7CTPdnUwT9jR',
amount: 0.05,
});
button.mount(el.value);
})
</script>
<template>
<div ref="el"></div>
</template>This snippet creates a payment button that looks like this: