Stripe Elements are automatically mounted to the DOM when you use Vue Stripe components. Understanding how they're mounted helps you integrate them effectively.
When you use a Vue Stripe element component, it:
div elementThe @ready event is emitted when the element is fully rendered and ready:
<script setup>
function handleReady() {
console.log('Payment Element is ready')
}
</script>
<template>
<PaymentElement @ready="handleReady" />
</template>
The @change event is emitted when element data changes:
<script setup>
function handleChange(event) {
if (event.complete) {
console.log('Card details are complete')
}
if (event.error) {
console.error('Error:', event.error.message)
}
}
</script>
<template>
<CardElement @change="handleChange" />
</template>
Elements are mounted inside a container div. The structure looks like:
<div id="payment-element">
<!-- Stripe Element is mounted here -->
</div>
Elements only mount when:
Elements or CheckoutProvider is availableElements are automatically cleaned up when:
Elements provider is removedv-if="false"You can control element mounting with v-if:
<script setup>
const shouldShowPayment = ref(false)
function showPayment() {
shouldShowPayment.value = true
}
</script>
<template>
<PaymentElement v-if="shouldShowPayment" />
</template>
For detailed information about element mounting and lifecycle, refer to the Stripe Element documentation.