【发布时间】:2021-07-14 12:15:30
【问题描述】:
我目前的工作解决方案。
<template>
<div>
<div ref="paypal"></div>
</div>
</template>
<script>
export default {
mounted: function () {
const script = document.createElement("script");
script.src = "https://www.paypal.com/sdk/js?client-id=SECRET";
script.addEventListener("load", this.setLoaded);
document.body.appendChild(script);
},
methods: {
openPaymentAmountModal() {
this.isPaymentAmountModalVisible = true;
},
closePaymentAmountModal() {
this.isPaymentAmountModalVisible = false;
},
setLoaded: function () {
window.paypal.Buttons({
createOrder: function (data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function (data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function (details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render(this.$refs.paypal);
}
}
}
</script>
在模态中,我不得不再次加载脚本。
如何在组件或页面级别的 NuxtJs 应用程序中全局加载此 Paypal 脚本?
【问题讨论】: