【发布时间】:2020-01-20 06:43:42
【问题描述】:
如何在 vuejs 中显示 paypal 的按钮?我已经在下面尝试了这些,它显示构建成功,但按钮没有显示。并且 bdw 输入字段显示,只有按钮没有。
这真的不可能发生吗,vuejs 中的 paypal?
<template>
<div id="container">
<input type="text" class="form-control">
<div id="paypal-button"></div>
</div>
</template>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
export default {
mounted() {
paypal.Button.render({
env: 'sandbox',
client: {
sandbox: 'ARQ-WKAkFn3g4C111Ud3lLaUAfzagvJ_pmkLKBVMASvv6nyjX3fv3j0gtBdJEDhRPznYP9sLtf9oiJfH',
production: 'EFNo9sAyqiOmnlRHsAdXiGBf6ULysEIfKUVsn58Pq6ilfGHVFn03iVvbWtfiht-irdJD_df1MECvmBC2'
},
locale: 'en_US',
style: {
size: 'medium',
color: 'gold',
shape: 'pill',
},
commit: true,
payment: function(data, actions) {
return actions.payment.create({
transactions: [{
amount: {
total: '11',
currency: 'USD'
}
}]
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
window.alert('Thank you for your purchase!');
});
}
}, '#paypal-button');
console.log('notification mounted');
}
}
</script>
我的控制台出错:
ReferenceError: "paypal is not defined"
我还尝试了其他功能
created() 和init(),但仍然没有显示。
【问题讨论】:
-
您的控制台有错误吗?
-
@Jerodev
Error in mounted hook: "ReferenceError: paypal is not defined" -
您导入一个脚本 (
checkout.js),它将在您的窗口对象上创建一个paypal对象/类。因此,如果您想访问它,只需执行window.paypal。 (确保检查它是否之前定义过)