我使用Stripe元素加载支付表单,但有时需要5-10秒才能完全加载表单。
有没有办法检测表单何时完全加载完成,这样我就可以在加载之前显示加载动画/图像?
console.log(“加载的API脚本”);
this.stripe=条纹(‘…………’);
const create_customer_response = JSON.parse(localStorage.getItem("create_customer_response"));
const client_secret = create_customer_response["intent"]["client_secret"]
const options = {
clientSecret: client_secret,
};
elements = this.stripe.elements(options);
const payment = elements.create('payment');
const paymentElement = document.getElementById('payment-element');
if (paymentElement) {
payment.mount(paymentElement);
this.isPaymentElementMounted = true; // Set the flag to true when the payment element is mounted
console.log('Payment element mounted successfully.');
console.log("this.stripe ", this.stripe);
console.log(elements);
this.spinner.hide();
} else {
console.error('#payment-element not found in the DOM. Make sure your template is correct.');
}
}
scriptElementStripe.onerror = () => {
// console.log('Could not load the Google API Script!');
}